HDU1452 Happy 2004 (因子和)
Happy 2004
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
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.
A test case of X = 0 indicates the end of input, and should not be processed.
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 }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。