BZOJ_2693_jzptab_莫比乌斯反演
Description
Input
一个正整数T表示数据组数
接下来T行 每行两个正整数 表示N、M
Output
T行 每行一个整数 表示第i组数据的结果
Sample Input
4 5
Sample Output
122
HINT
T <= 10000
N, M<=10000000
$sumlimits_{i=1}^{n}sumlimits_{j=1}^{m}lcm(i,j)$
$=sumlimits_{i=1}^{n}sumlimits_{j=1}^{m}frac{i*j}{gcd(i,j)}$
$=sumlimits_{p=1}^{n}sumlimits_{i=1}^{lfloorfrac{n}{p}
floor}
sumlimits_{j=1}^{lfloorfrac{m}{p}
floor} i*j*p*[gcd(i,j)=1]$
$=sumlimits_{p=1}^{n}psumlimits_{i=1}^{lfloorfrac{n}{p}
floor}
sumlimits_{j=1}^{lfloorfrac{m}{p}
floor} i*j
sumlimits_{d|gcd(i,j)}mu(d)$
$=sumlimits_{p=1}^{n}p
sumlimits_{d=1}^{n/p}mu(d)*d^{2}
sumlimits_{i=1}^{lfloorfrac{n/p}{d}
floor}
sumlimits_{j=1}^{lfloorfrac{m/p}{d}
floor} i*j
$
设$s[n]=sumlimits_{i=1}^{n}i$
$=sumlimits_{p=1}^{n}p
sumlimits_{d=1}^{n/p}mu(d)*d^{2}*
s[lfloorfrac{n/p}{d}
floor]*
s[lfloorfrac{m/p}{d}
floor]
$
设$Q=d*p,先枚举Q$
$=sumlimits_{Q=1}^{n}
s[lfloorfrac{n}{Q}
floor]*
s[lfloorfrac{m}{Q}
floor]
sumlimits_{d|Q}mu(d)*d^{2}*lfloorfrac{Q}{d}
floor
$
设$f[n]=sumlimits_{d|n}mu(d)*d^{2}*lfloorfrac{n}{d}
floor
=nsumlimits_{d|n}mu(d)*d$
$=sumlimits_{Q=1}^{n}
s[lfloorfrac{n}{Q}
floor]*
s[lfloorfrac{m}{Q}
floor]*f[Q]
$
$然后发现f[n]=n*g[n],g[n]为 id卷mu 的积性函数$
$我们可以处理出f[n]的前缀和,然后O(sqrt{n})处理即可$
$mdlswl$