Lucy's Algorithm
Define S(n,pi) as the sum in a sieve after sieving the prime pi.
π function
If each number in the sieve contributes its value in the k-th power if it's prime and 0 otherwise, then the sum in the sieve:
S(n,pi)=S(n,pi−1)−pik(S(n/pi,pi−1)−S(p−1,pi−1))
It's enough to sieve until n to mark all the numbers in the sieve as primes or not, then:
π(n)=S(n,n)=S(n,pi−1)−(S(n/pi,pi−1)−S(p−1,pi−1))Π(n)=S(n,n)=S(n,pi−1)−pi(S(n/pi,pi−1)−S(p−1,pi−1))
and the base case is −1+∑i≤nik.
Hyperbola method
Let:
(f∗g)(n)=d∣n∑f(n)g(n/d)=ab=n∑f(a)g(b)
then:
n≤x∑(f∗g)(n)=n≤x∑ab=n∑f(a)g(b)=ab≤x∑f(a)g(b)=a≤α∑b≤x/a∑f(a)g(b)+b≤β∑a≤x/b∑f(a)g(b)−a≤αb≤β∑f(a)g(b)
Commonly, α=β=n are the efficient values.
φ and Φ functions
Using hyperbola method
Let f(n)=φ(n) and g(n)=1:
i=1∑nd∣i∑φ(d)=a≤n∑b≤n/a∑φ(a)+b≤n∑a≤n/b∑φ(a)−a≤n∑b≤n∑φ(a)i=1∑ni=a≤n∑φ(a)an+b≤n∑a≤n/b∑φ(a)−a≤n∑φ(a)nT(n)=a≤n∑φ(a)an+b=2∑na≤n/b∑φ(a)+k≤n∑φ(k)−na≤n∑φ(a)
k≤n∑φ(k)=T(n)−a≤n∑φ(a)an−b=2∑na≤n/b∑φ(a)+na≤n∑φ(a)Φ(n)=T(n)−a≤n∑φ(a)an−b=2∑nΦ(n/b)+nΦ(n)
μ and M functions
Using hyperbola method
Let f(n)=μ(n) and g(n)=1:
i=1∑nd∣i∑μ(d)=a≤n∑b≤n/a∑μ(a)+b≤n∑a≤n/b∑μ(a)−a≤n∑b≤n∑μ(a)1=a≤n∑μ(a)an+b≤n∑k≤n/b∑μ(k)−a≤n∑μ(a)n=a≤n∑μ(a)an+k≤n∑μ(k)+b=2∑nk≤n/b∑μ(k)−a≤n∑μ(a)n
k≤n∑μ(k)=1−a≤n∑μ(a)an−b=2∑nk≤n/b∑μ(k)+a≤n∑μ(a)nM(n)=1−a≤n∑μ(a)an−b=2∑nM(bn)+nM(n)
Misc.
Statement
i=1∑Nμ(i)2=i=1∑⌊N⌋μ(i)⌊i2N⌋
Proof
Let
μ(n)2=k2∣n∑μ(k)
then:
i=1∑Nμ(i)2=i=1∑Nk2∣i∑μ(k)=i=1∑Nk=1∑Nk2∣iμ(k)=k=1∑Nμ(k)i=1∑Nk2∣i=k=1∑Nμ(k)⌊k2N⌋
Resources