ShinriiTin's Blog - 博主是sb

math

S(n) = ∑i∈[1,n]j∈[1,n] F(i,j),n<=109

    F(i,j) = ∑d∈[1,i*j] [d | i*j]

 

1. 化简S(n)

step 1.

    F(i,j) = ∑d∈[1,i*j] [d/gcd(i,d) | i*j/gcd(i,d)]

             = d∈[1,i*j] [d/gcd(i,d) | j]

step 2.

    S(n) = i∈[1,n]j∈[1,n]d∈[1,i*j] [d/gcd(i,d) | j]

           = i∈[1,n]d∈[1,i*n] [n/(d/gcd(i,d)]

           = i∈[1,n]d∈[1,i*n] [n*gcd(i,d)/d]

step 3.

    S(n) = i∈[1,n]d∈[1,i*n]k [gcd(i,d)==k]*[n*k/d]

           = ki∈[1,n/k]d∈[1,n] [gcd(i,d)==1]*[n/d]

    S(n) = i∈[1,n]d∈[1,n]k∈[1,n/i] [gcd(i,d)==1]*[n/d]

            = i∈[1,n]d∈[1,n] [gcd(i,d)==1]*[n/d]*[n/i]

    S(n) = i∈[1,n]j∈[1,n] [gcd(i,j)==1]*[n/i]*[n/j]

step 4.

    S(n) = ∑d μ(d)*∑i∈[1,n/d]j∈[1,n/d] [n/(id)]*[n/(jd)]

           = d μ(d)*∑i∈[1,n/d] [n/(id)]*j∈[1,n/d] [n/(jd)]

    令g(n) = ∑i∈[1,n] [n/i],则S(n) = d μ(d)*g([n/d])2

    只计算所有不同的[n/d],可以做到O(n2/3)

 

2.0 计算M(n) = ∑i∈[1,n] μ(i)

    M(n) = ∑i∈[1,n] μ(i)

            = i∈[1,n] (∑d|i μ(d) - ∑d|i,d<i μ(d))

            = 1 - i∈[1,n]d|i,d<i μ(d)

            = 1 - d|i,d<ii∈[1,n] μ(d)

            = 1 - ∑d∈[1,n] i∈[2,n/d] μ(d)

            = 1 - i∈[2,n] d∈[1,n/i] μ(d)

            = 1 - ∑i∈[2,n] M([n/i])

    筛出n2/3以内的M,查询的时候查表O(1)回答.

    对于大于n2/3的情况,我们用hash表来记忆化.

    这样能做到O(n2/3)的复杂度.

 

2.1 计算F(n) = ∑i∈[1,n] phi(i)

     由n = ∑d|n phi(d) ,我们可以类似地得到F(n)的计算方法

     F(n) = ∑i∈[1,n] phi(i)

            = i∈[1,n] (∑d|i phi(d) - ∑d|i,d<i phi(d))

            = n(n+1)/2 - i∈[1,n]d|i,d<i phi(d)

            = n(n+1)/2 - i∈[2,n] F([n/i])

 

3. 码码码