传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6833
借鉴大佬: https://blog.csdn.net/weixin_44282912/article/details/107844614 https://blog.csdn.net/oampamp1/article/details/107865300
求 解 ∑ a 1 = 1 n ∑ a 2 = 1 n . . . ∑ a x = 1 n ( ∏ j = 1 x a j k ) f ( g c d ( a 1 , a 2 . . . a x ) ) g c d ( a 1 , a 2 . . . a x ) 求解\sum_{a_1=1}^n\sum_{a_2=1}^n...\sum_{a_x=1}^n\left(\prod_{j=1}^xa_j^k\right)f(gcd(a_1,a_2...a_x))gcd(a_1,a_2...a_x) 求解a1=1∑na2=1∑n...ax=1∑n(j=1∏xajk)f(gcd(a1,a2...ax))gcd(a1,a2...ax)
令 d = g c d ( a 1 , a 2 . . . a x ) 得 : 令d=gcd(a_1,a_2...a_x)得: 令d=gcd(a1,a2...ax)得:
∑ a 1 = 1 n ∑ a 2 = 1 n . . . ∑ a x = 1 n ( ∏ j = 1 x a j k ) f ( d ) d \sum_{a_1=1}^n\sum_{a_2=1}^n...\sum_{a_x=1}^n\left(\prod_{j=1}^xa_j^k\right)f(d)d a1=1∑na2=1∑n...ax=1∑n(j=1∏xajk)f(d)d
枚 举 d 得 : 枚举d得: 枚举d得:
∑ d = 1 n d f ( d ) ∑ a 1 = 1 n ∑ a 2 = 1 n . . . ∑ a x = 1 n ( ∏ j = 1 x a j k ) [ g c d ( a 1 , a 2 . . . a x ) = d ] \sum_{d=1}^ndf(d)\sum_{a_1=1}^n\sum_{a_2=1}^n...\sum_{a_x=1}^n\left(\prod_{j=1}^xa_j^k\right)[gcd(a_1,a_2...a_x)=d] d=1∑ndf(d)a1=1∑na2=1∑n...ax=1∑n(j=1∏xajk)[gcd(a1,a2...ax)=d]
∑ d = 1 n d k x + 1 f ( d ) ∑ a 1 = 1 ⌊ n d ⌋ ∑ a 2 = 1 ⌊ n d ⌋ . . . ∑ a x = 1 ⌊ n d ⌋ ( ∏ j = 1 x a j k ) [ g c d ( a 1 , a 2 . . . a x ) = 1 ] \sum_{d=1}^nd^{kx+1}f(d)\sum_{a_1=1}^{\left \lfloor \frac{n}{d} \right \rfloor }\sum_{a_2=1}^{\left \lfloor \frac{n}{d} \right \rfloor }...\sum_{a_x=1}^{\left \lfloor \frac{n}{d} \right \rfloor }\left(\prod_{j=1}^xa_j^k\right)[gcd(a_1,a_2...a_x)=1] d=1∑ndkx+1f(d)a1=1∑⌊dn⌋a2=1∑⌊dn⌋...ax=1∑⌊dn⌋(j=1∏xajk)[gcd(a1,a2...ax)=1]
∑ d = 1 n d k x + 1 f ( d ) ∑ a 1 = 1 ⌊ n d ⌋ ∑ a 2 = 1 ⌊ n d ⌋ . . . ∑ a x = 1 ⌊ n d ⌋ ( ∏ j = 1 x a j k ) ∑ t ∣ a 1 t ∣ a 2 . . . t ∣ a x μ ( t ) \sum_{d=1}^nd^{kx+1}f(d)\sum_{a_1=1}^{\left \lfloor \frac{n}{d} \right \rfloor }\sum_{a_2=1}^{\left \lfloor \frac{n}{d} \right \rfloor }...\sum_{a_x=1}^{\left \lfloor \frac{n}{d} \right \rfloor }\left(\prod_{j=1}^xa_j^k\right)\sum_{t|a_1\;t|a2\;...\;t|a_x}\mu(t) d=1∑ndkx+1f(d)a1=1∑⌊dn⌋a2=1∑⌊dn⌋...ax=1∑⌊dn⌋(j=1∏xajk)t∣a1t∣a2...t∣ax∑μ(t)
∑ d = 1 n d k x + 1 f ( d ) ( ∑ i = 1 ⌊ n d ⌋ i k ) x ∑ t ∣ a 1 t ∣ a 2 . . . t ∣ a x μ ( t ) \sum_{d=1}^nd^{kx+1}f(d)\left (\sum_{i=1}^{\left \lfloor \frac{n}{d} \right \rfloor }i^k\right)^x\sum_{t|a_1\;t|a2\;...\;t|a_x}\mu(t) d=1∑ndkx+1f(d)⎝⎜⎛i=1∑⌊dn⌋ik⎠⎟⎞xt∣a1t∣a2...t∣ax∑μ(t)
枚 举 t 得 : 枚举t得: 枚举t得:
∑ d = 1 n d k x + 1 f ( d ) ∑ t = 1 ⌊ n d ⌋ μ ( t ) ( ∑ i = 1 ⌊ n d t ⌋ ( i t ) k ) x \sum_{d=1}^nd^{kx+1}f(d)\sum_{t=1}^{\left \lfloor \frac{n}{d} \right \rfloor }\mu(t)\left (\sum_{i=1}^{\left \lfloor \frac{n}{dt} \right \rfloor }(it)^k\right)^x d=1∑ndkx+1f(d)t=1∑⌊dn⌋μ(t)⎝⎜⎛i=1∑⌊dtn⌋(it)k⎠⎟⎞x
∑ d = 1 n d k x + 1 f ( d ) ∑ t = 1 ⌊ n d ⌋ μ ( t ) t k x ( ∑ i = 1 ⌊ n d t ⌋ i k ) x \sum_{d=1}^nd^{kx+1}f(d)\sum_{t=1}^{\left \lfloor \frac{n}{d} \right \rfloor }\mu(t)t^{kx}\left (\sum_{i=1}^{\left \lfloor \frac{n}{dt} \right \rfloor }i^k\right)^x d=1∑ndkx+1f(d)t=1∑⌊dn⌋μ(t)tkx⎝⎜⎛i=1∑⌊dtn⌋ik⎠⎟⎞x
令 T = d t 并 枚 举 T 得 : 令T=dt并枚举T得: 令T=dt并枚举T得:
∑ T = 1 n ( ∑ i = 1 ⌊ n d t ⌋ i k ) x T k x ∑ d ∣ T d f ( d ) μ ( T d ) \sum_{T=1}^n\left (\sum_{i=1}^{\left \lfloor \frac{n}{dt} \right \rfloor }i^k\right)^xT^{kx}\sum_{d|T}df(d)\mu(\frac{T}{d}) T=1∑n⎝⎜⎛i=1∑⌊dtn⌋ik⎠⎟⎞xTkxd∣T∑df(d)μ(dT)
令 g ( T ) = ∑ d ∣ T d f ( d ) μ ( T d ) , 则 令g(T)=\sum_{d|T}df(d)\mu(\frac{T}{d}),则 令g(T)=∑d∣Tdf(d)μ(dT),则
∑ T = 1 n ( ∑ i = 1 ⌊ n T ⌋ i k ) x T k x g ( T ) \sum_{T=1}^n\left (\sum_{i=1}^{\left \lfloor \frac{n}{T} \right \rfloor }i^k\right)^xT^{kx}g(T) T=1∑n⎝⎜⎛i=1∑⌊Tn⌋ik⎠⎟⎞xTkxg(T)
O ( n l o g n ) 筛 f 和 g , 并 对 T k x g ( T ) 和 ∑ i = 1 ⌊ n T ⌋ i k 做 前 缀 和 , 最 后 n 分 块 计 算 , 复 杂 度 为 O ( n l o g n + T n ) \red{O(nlogn)筛f和g,并对T^{kx}g(T)和\sum_{i=1}^{\left \lfloor \frac{n}{T} \right \rfloor }i^k做前缀和,最后\sqrt n分块计算,复杂度为O(nlogn+T\sqrt n)} O(nlogn)筛f和g,并对Tkxg(T)和∑i=1⌊Tn⌋ik做前缀和,最后n 分块计算,复杂度为O(nlogn+Tn )