hdu 1452

想要计算2004^x的所有因子和对29求余结果

 

2004^x=2^2x*3^x*167^x

 

用sum(T)表示T的所有因子和

则sum(2004^x)%29=sum(2^2x)%29*sum(3^x)%29*sum(167^x)%29

                                =sum(2^2x)%29*sum(3^x)%29*sum(22^x)%29 

                                =(2^(2X+1)-1)%29* (3^(X+1)-1)/2%29  *(22^(X+1)-1)/21%29

 

因为有(a*b)/c %M= a%M* b%M  * inv(c)
 c*inv(c)%M=1    inv(c)是所有数满足上式的数中为最小的

so inv(2)=15. inv(21)=18

=>  s(2004^X) =(2^(2X+1)-1)* (3^(X+1)-1)*15 *(22^(X+1)-1)*18

 

你可能感兴趣的:(c)