H = F ∗ G H ( n ) = ∑ d ∣ n F ( d ) G ( n d ) H=F*G\\ H(n)=\sum_{d|n} F(d)G(\frac{n}{d}) H=F∗GH(n)=d∣n∑F(d)G(dn)
H = F G H ( n ) = F ( n ) − ∑ d ∣ n , d ≠ 1 G ( d ) H ( n d ) G ( 1 ) H=\frac{F}{G}\\ H(n)=\frac{F(n)-\sum_{d|n,d\neq 1} G(d)H(\frac {n}{d})}{G(1)} H=GFH(n)=G(1)F(n)−∑d∣n,d=1G(d)H(dn)
推导:
H = F G F = G ∗ H F ( n ) = ∑ d ∣ n G ( d ) H ( n d ) F ( n ) = G ( 1 ) H ( n ) + ∑ d ∣ n , d ≠ 1 G ( d ) H ( n d ) G ( 1 ) H ( n ) = F ( n ) − ∑ d ∣ n , d ≠ 1 G ( d ) H ( n d ) H ( n ) = F ( n ) − ∑ d ∣ n , d ≠ 1 G ( d ) H ( n d ) G ( 1 ) H=\frac{F}{G}\\ F=G*H\\ F(n)=\sum_{d|n} G(d)H(\frac{n}{d})\\ F(n)=G(1)H(n)+\sum_{d|n,d\neq 1} G(d)H(\frac {n}{d})\\ G(1)H(n)=F(n)-\sum_{d|n,d\neq 1} G(d)H(\frac {n}{d})\\ H(n)=\frac{F(n)-\sum_{d|n,d\neq 1} G(d)H(\frac {n}{d})}{G(1)}\\ H=GFF=G∗HF(n)=d∣n∑G(d)H(dn)F(n)=G(1)H(n)+d∣n,d=1∑G(d)H(dn)G(1)H(n)=F(n)−d∣n,d=1∑G(d)H(dn)H(n)=G(1)F(n)−∑d∣n,d=1G(d)H(dn)
g ( n ) = ∑ d ∣ n f ( n ) g(n)=\sum_{d|n} f(n) g(n)=d∣n∑f(n)
对于
i = p 1 u 1 × p 2 u 2 × . . . × p n u n j = p 1 v 1 × p 2 v 2 × . . . × p m v n m ≤ n , v k ≤ u k i=p_1^{u_1}\times p_2^{u_2}\times ...\times p_n^{u_n}\\ j=p_1^{v_1}\times p_2^{v_2}\times ...\times p_m^{v_n}\\ m\leq n,v_k\leq u_k i=p1u1×p2u2×...×pnunj=p1v1×p2v2×...×pmvnm≤n,vk≤uk
g ( i ) g(i) g(i) 中含有 f ( j ) f(j) f(j)
于是将每个数质因数分解,每个质因数看作一个维度,指数看作下标
狄利克雷前缀和即求 n 维前缀和
先线性筛,然后用埃氏筛统计前缀和
for(int i=1;i<=tot;i++)
for(int j=1;pri[i]*j<=n;j++)
a[pri[i]*j]+=a[j];
时间复杂度: O ( n l o g l o g n ) O(nloglogn) O(nloglogn)
F ( n ) = ∑ d ∣ n f ( d ) f ( n ) = ∑ d ∣ n μ ( d ) F ( n d ) F(n)=\sum_{d|n} f(d)\\ f(n)=\sum_{d|n} \mu(d)F(\frac{n}{d}) F(n)=d∣n∑f(d)f(n)=d∣n∑μ(d)F(dn)
[ g c d ( i , j ) = = 1 ] = ∑ d ∣ g c d ( i , j ) μ ( d ) [gcd(i,j)==1]=\sum_{d|gcd(i,j)} \mu(d) [gcd(i,j)==1]=d∣gcd(i,j)∑μ(d)
证明:
μ = e 1 e = μ ∗ 1 \mu=\frac{e}{1}\\ e=\mu * 1 μ=1ee=μ∗1
a n s = ∑ a 1 , a 2 , . . . , a n ( F 1 ( a 1 ) × F 2 ( a 2 ) × . . . × F n ( a n ) ) × G ( ∏ a i ) 令 H = F 1 ∗ F 2 ∗ . . . ∗ F n , d 为 a k 的 积 a n s = ∑ d H ( d ) × G ( d ) ans=\sum_{a_1,a_2,...,a_n} (F_1(a_1)\times F_2(a_2)\times ...\times F_n(a_n))\times G(\prod a_i)\\ 令 H=F_1*F_2*...*F_n,d为 a_k 的积\\ ans=\sum_d H(d)\times G(d) ans=a1,a2,...,an∑(F1(a1)×F2(a2)×...×Fn(an))×G(∏ai)令H=F1∗F2∗...∗Fn,d为ak的积ans=d∑H(d)×G(d)