日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 1452】 Happy 2004(因子和,逆元,快速幂)

發布時間:2023/12/10 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 1452】 Happy 2004(因子和,逆元,快速幂) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Happy 2004

Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1863????Accepted Submission(s): 1361


?

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.

?

?

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.

?

?

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

?

?

Source

ACM暑期集訓隊練習賽(六)

?

題意:求2004^x的所有因子和對29取余的結果。

?

題解:因為所有數都可以被分解成a=p1^c1*p2^c2*...*pk^ck,并有約數和定理:sum=(p1^0+...+p1^c1)*(p2^0+...+p2^c1)*...*(pk^0+...+pk^ck)。每一項可以通過等比數列求和得到。2004=2^2*3*167,所以答案就是2^(2*n+1)*3^(n+1)*167^(n+1)/(2*166)。由于需要取余,所以不能直接除要求出2*166的逆元改為相乘。

?

AC代碼:

#include<bits/stdc++.h> #define debug cout<<"aaa"<<endl #define mem(a,b) memset(a,b,sizeof(a)) #define LL long long #define lson l,mid,root<<1 #define rson mid+1,r,root<<1|1 #define MIN_INT (-2147483647-1) #define MAX_INT 2147483647 #define MAX_LL 9223372036854775807i64 #define MIN_LL (-9223372036854775807i64-1) using namespace std;const int N = 100000 + 5; const int mod = 29;int e_gcd(int a,int b,int &x,int &y) {if(b==0) {x=1,y=0;return a;}int q=e_gcd(b,a%b,y,x);y-=a/b*x;return q;}int quick(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 main(){int n,x,y,a,b,c,ans;exgcd(166*2,29,x,y);while(~scanf("%d",&n)&&n){a=(quick(2,2*n+1)-1)%mod;b=(quick(3,n+1)-1)%mod;c=(quick(167,n+1)-1)%mod;ans=((a*b*c*x)%mod+mod)%mod;printf("%d\n",ans);}return 0; }

?

總結

以上是生活随笔為你收集整理的【HDU - 1452】 Happy 2004(因子和,逆元,快速幂)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。