標籤:des style blog http color io os ar java
Happy 2004
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Problem DescriptionConsider a positive integer X,and let S be the sum of all positive integer divisors of 2004^X. Your job is to determine S modulo 29 (the rest of the division of S by 29).
Take X = 1 for an example. The positive integer divisors of 2004^1 are 1, 2, 3, 4, 6, 12, 167, 334, 501, 668, 1002 and 2004. Therefore S = 4704 and S modulo 29 is equal to 6.
InputThe input consists of several test cases. Each test case contains a line with the integer X (1 <= X <= 10000000).
A test case of X = 0 indicates the end of input, and should not be processed.
OutputFor each test case, in a separate line, please output the result of S modulo 29.
Sample Input1100000
Sample Output610 Source ACM暑期集訓隊練習賽(六)
Recommendlcy | We have carefully selected several similar problems for you: 1695 1573 1788 1060 1370 首先2004 = 2*2*3*167然後,利用因子和是積性函數的性質(蒟蒻準備專門寫一篇持續更新的有關積性函數證明及學習的文章):σ(2004^x) = σ(2^2x) * σ (3^x) * σ(167^x) Mod 29∵167≡22(Mod29)故σ(2004^x) = σ(2^2x) * σ (3^x) * σ(22^x) Mod 29 = [2^(2x+1)-1][3^(x+1)-1]/2*[22^(x+1)-1]/21因為2的模29乘法逆元為15 ,22的模29乘法逆元為18故σ(2004^x) = [2^(2x+1)-1][3^(x+1)-1]*15*[22^(x+1)-1]*18即可用快速冪求解
1 #include<set> 2 #include<queue> 3 #include<vector> 4 #include<cstdio> 5 #include<cstdlib> 6 #include<cstring> 7 #include<iostream> 8 #include<algorithm> 9 using namespace std;10 const int Mod = 29;11 #define Rep(i,n) for(int i=1;i<=n;i++)12 #define For(i,l,r) for(int i=l;i<=r;i++)13 14 int ans,x;15 16 int quickpow(int m,int n){17 int ans=1;18 while(n){19 if(n&1) ans=(ans*m)%Mod;20 m=(m*m)%Mod;21 n>>=1; 22 }23 return ans%Mod;24 }25 26 int main(){27 while(scanf("%d",&x),x){28 int ans=0;29 ans=(quickpow(2,2*x+1)-1)%Mod;30 ans=ans%Mod*(quickpow(3,x+1)-1)*15%Mod;31 ans=ans%Mod*(quickpow(22,x+1)-1)*18%Mod;32 printf("%d\n",ans%Mod);33 }34 return 0;35 }View Code
HDU1452 Happy 2004 (因子和)