Happy 2004 hdu1452

來源:互聯網
上載者:User

標籤: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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.