標籤:sts rest app for ica sub BMI other \n
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2021 Accepted Submission(s): 1474
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 數論題,推理挺麻煩的:題目的大意是說求2004^n的全部因子之和。根據唯一分解定理2004=(2^2)*3*167,則2004^n=(2^2n)*(3^n)*(167^n);又有結論:一個因數的因子和是一個積性函數。設f(x)為x的因子和,則f(ab)=f(a)*f(b);則f(2004^n)=f(2^2n)*f(3^n)*f(167^n).繼續上結論:如果一個數是素數,那麼f(a^n)=1+a+a^2+a^3+.......a^n=(a^(n+1)-1)/(a-1);考慮到 167%29=22;則f(2004^n)=(2^(2n+1)-1) * (3^(n+1)-1)/2 * (22^(n+1)-1)/21;接著上逆元: (a*b/c)%mod=a%mod*b%mod*inv(c);其中inv(c)表示(c*inv(c))%mod=1的最小整數. mod=29,則inv(1)=1;inv(2)=15;inv(21)=18;則原式=(2^(2n+1)-1)*(3^(n+1)-1)%mod*inv(2)* (22^(n+1)-1)*inv(21)15*18%29=9---------------則原式(2^(2n+1)-1) * (3^(n+1)-1)* (22^(n+1)-1)*9%29;
#include <iostream>#include <bits/stdc++.h>using namespace std;typedef long long ll;int ans=0;const int mod=29;ll quick_mod(ll k,ll n){ ll res=1; while(n>0) { if(n&1) { res=(res*k)%mod; } k=k*k%mod; n>>=1; } res--; if(res<0) res+=29; return res;}int main(){ ll n; while(~scanf("%lld",&n)&&n) { ans=quick_mod(2,2*n+1)*quick_mod(3,n+1)*quick_mod(22,n+1)*9%mod; printf("%d\n",ans); } return 0;}
Happy 2004 hdu1452