Topic Links: Transmission Door
Test instructions
To 2004^x all the approximate and.
Analysis:
By the unique decomposition theorem
X=p1^a1*p2^a2*...*pn^an
Then its approximate sum = (P1^0+P1^1^...+P1^A1) *...* (PN^0+PN^1^...+PN)
The code is as follows:
#include <iostream> #include <cstring> #include <algorithm> #include <cstdio>using namespace std;const int mod = 29;int quick_mod (int a,int b) { int ans = 1; while (b) { if (b&1) ans=ans*a%mod; b>>=1; A=a*a%mod; } return ans;} int fac[10],cnt;int num[10];void init () { int n = 2004; CNT = 0; memset (num,0,sizeof (num)); for (int i=2;i*i<=n;i++) { if (n%i==0) { fac[cnt]=i; while (n%i==0) n/=i,num[cnt]++; cnt++; } } if (n>1) fac[cnt]=n,num[cnt++]=1;} int main () { int n; while (~SCANF ("%d", &n) &&n) { init (); int ans = 1; for (int i=0;i<cnt;i++) { num[i]*=n; int INV = Quick_mod (fac[i]-1,mod-2); Ans=ans* ((Quick_mod (fac[i],num[i]+1) -1+mod) *inv%mod)%mod; } printf ("%d\n", ans); } return 0;}
HDU 1452 Happy 2004 (unique decomposition theorem)