zoukankan      html  css  js  c++  java
  • (转载)有关反演和gcd

    tips :

    积性函数 F (n) = Π F (piai )

    若F (n), G (n)是积性函数则

    F (n) * G (n)

    Σd | n F (n)

    是积性函数

    n = Σd | n  φ (d)

    1 = Σd | n  μ (d)

    Σgcd (i, n) = 1 i = n * φ (n) / 2

    Problem1

    F (n) = Σ1<= i <= n gcd(i, n), n <= 1000000

    Sol

    枚举结果

    F (n) = Σd | n d * Σgcd (i, n) = d 1

    F (n) = Σd | n d * Σgcd (i / d, n / d) = 1 1

    F (n) = Σd | n d * Σgcd (i / d, n / d) = 1 1

    F (n) = Σd | n d * φ (n / d)

    单次计算O (sqrt N)

    筛法O (N)

    Problem 2

    F (n) = Σ1<= i <= n gcd (i, n), n <= 2147483647               (POJ longge's problem)

    Sol

    由P1可知F (n)是积性函数 因此考虑计算F (pk)

    由P1 易知

    F (pk) = p * F (pk - 1)  + (p - 1)pk - 1

    单个F(n)可以O (sqrt N)时间有他的质因子分解计算得到

    Problem 3

     F (n) = Σ1<= i <= n lcm(i, n), n <= 1000000             (SPOJ LCMSUM)

     

    显而易见的变形

    F (n) = Σ1<= i <= n i * n / gcd (i, n)

    F (n) =Σd | n  Σgcd (i, n) = d i * n / d

    F (n) =Σd | n n / d * Σgcd (i, n) = d i

    F (n) =Σd | n n / d * Σgcd (i / d, n / d) = 1 i

    F (n) =Σd | n n / d * d * Σgcd (i / d, n / d) = 1 i / d

    令j = i / d

    F (n) =Σd | n n * Σgcd (j, n / d) = 1 j

    由Σgcd (i, n) = 1 i = n * φ (n) / 2

    F (n) =Σd | n n * (n / d) * φ (n / d) / 2

    F (n) =n * Σd | n (n / d) * φ (n / d) / 2

    F (n) =n / 2 * Σd | n d * φ (d)

    筛出 Σd | n d * φ (d)     O (N)-O(1)

    Problem 4

    F (n) = Σ1<= i <= n Σ1<= j <= n gcd (i, j)      n <= 1000000          (SPOJ GCDEX)

    Sol

    G (n) = Σd | n d * φ (n / d)

    F (n) = Σ1<= i <= n G (i)

    筛出G (i) 前缀和

    Problem 5

    求F (n, m) = [n / d] * [m / d]

    Sol

    研究退化情况 m = 1 F (n) = [n / d]

    共有sqrt n种不同取值 

    F (n, m) = [n / d] * [m / d]

    共有sqrt n + sqrt m种不同取值  归并这两种取值

    Problem 6

    多组询问n, m 求F (n, m) = Σ1<= i <= n Σ1<= j <= m gcd (i, j)

    Sol

    F (n, m) = Σ1<= i <= n Σ1<= j <= m Σ d | gcd (i, j) φ (d)

    F (n, m) = Σ d φ (d) Σ1<= i <= n d | i Σ1<= j <= m d | j 1

    F (n, m) = Σ d φ (d) * [n / d] * [m / d]

    可以经P5解决

    Problem 6

    多组询问n, m 求F (n, m) = Σ1<= i <= n Σ1<= j <= m gcd (i, j) = 1 1

    Sol

    F (n, m) = Σ1<= i <= n Σ1<= j <= m Σ d | gcd (i, j) μ (d)

    F (n, m) = Σ d μ (d) Σ1<= i <= n d | i Σ1<= j <= m d | j 1

    F (n, m) = Σ d μ (d) * [n / d] * [m / d]

    可以经P5解决

     

    Problem 7

    F (n, m) = Σ1<= i <= n Σ1<= j <= m Σ gcd (i, j) <- prime 1            (BZOJ YY的GCD)

    Sol

    F (n, m) = Σ1<= i <= n Σ1<= j <= m Σ gcd (i, j) <- prime 1

    F (n, m) = Σ1<= i <= n Σ1<= j <= m Σ p <- prime gcd (i, j) = p 1

    F (n, m) = Σ p <- prime Σ1<= i <= n Σ1<= j <= m  gcd (i, j) = p 1

    F (n, m) = Σ p <- prime Σ1<= i <= n / p Σ1<= j <= m / p gcd (n / p, m / p) = 1  1

    可以经P6解决

  • 相关阅读:
    noip模拟赛(一)宠物之战
    noip模拟赛(一)魔法树
    luogu1097统计数字[noip2007提高组Day1T1]
    luogu1207双重回文数[usaco1.2]Dual Palindromes
    【2018.9.20】JOI 2017 Final T3「JOIOI 王国 / The Kingdom of JOIOI」
    【2018.9.20】JOI 2017 Final T2「準急電車 / Semiexpress」
    Codeforces Round #510
    【2018.9.15】陈老师模拟赛1
    【loj6191】「美团 CodeM 复赛」配对游戏
    【loj6029】「雅礼集训 2017 Day1」市场
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/3808676.html
Copyright © 2011-2022 走看看