Total Submission(s): 609 Accepted Submission(s): 431
Problem Description
Consider 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.
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.
Input
The 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.
A test case of X = 0 indicates the end of input, and should not be processed.
Output
For each test case, in a separate line, please output the result of S modulo 29.
Sample Input
1 10000 0
Sample Output
6 10题意:关于求一个数所有因子之和的问题,一种是等比数列求和,一种是乘法逆元。对于这一题我只能说我SB了,明知道hdu不支持long long类型(如果使用就会超时),却视而不见,导致对自己的算法产生了怀疑,疯狂调试了近两个小时,还是木有找出错误,最后蓦然发现我却用了long long 类型,着实伤不起啊!!有木有,,,,法一:#include<iostream> #include<string.h> #include<string> #define N 29 #include<cstdio> using namespace std; int a[][3]={2,3,167,2,1,1}; typedef __int64 L; L pow(L a,L b) { L ans=1; while(b) { if(1&b) ans=(ans*a)%N; a=(a%N*a%N)%N; b=b>>1; } return ans; } L _pow(L a,L b) { if(a==0) return 0; else if(a==1||b==0) return 1; else { if(1&b) return (_pow(a,b/2)%N)*((1+pow(a,b/2+1))%N); else return ((_pow(a,b/2-1)%N)*((1+pow(a,b/2+1))%N)+pow(a,b/2))%N; } } int main() { L x; while(~scanf("%I64d",&x),x) { L ans=1; for(int i=0;i!=3;++i) ans=(ans%N*(_pow(a[0][i],a[1][i]*x)%N))%N; printf("%I64d\n",ans); }return 0; }
法二:(a+k*29)^29%29=a%29;*#include<cstdio> #include<string.h> #include<iostream> #define N 29 using namespace std; typedef __int64 L; L _pow(L a,L b) { L ans=1; while(b) { if(1&b) ans=(ans*a)%N; a=(a%N*a%N)%N; b=b>>1; } return ans; } int main() { L x; while(~scanf("%I64d",&x),x) { L a=_pow(2,(x*2+1)); L b=_pow(3,(x+1)); L c=_pow(22,(x+1)); L d=((a-1)*(b-1)*15*(c-1)*18)%N; printf("%I64d\n",d); }return 0;