因子和

http://acm.hdu.edu.cn/showproblem.php?pid=1452

 1 /**
 2 因子和问题:
 3 S(6)=1+2+3+6=12;S(5)=1+5=6;
 4 S(30)=1+2+3+5+6+10+15+30=72;
 5 可知:
 6 S(30)=S(5*6)=S(5)*S(6);
 7 因子和积性函数,当gcd(a,b)=1时要S(a*b)=S(a)*S(b)
 8 如果p是素数
 9 S(p^n)=1+p+p^2+p^3+……+p^n=(p^(n+1)-1)/(p-1)
10 
11 %运算法则 1. (a*b)%p=(a%p)*(b%p)
12 %运算法则 2. (a/b)%p=(a*b^(-1)%p)
13 b^(-1)是b模p的逆元,即a*b%p=1;
14 例如:
15 2的逆元素是15 (%29),因为2*15=30%29=1
16 21的逆元素是18 (%29),因为21*18=378%29=1
17 **/
18 //求2004^x的因子和
19 #include <iostream>
20 using namespace std;
21 int kpow(int a,int n,int mod)
22 {
23     int ans;
24     if(n==0) return 1;
25     int temp=kpow(a,n/2,mod)%mod;
26     ans=temp*temp%mod;
27     if(n%2) ans=temp*temp*a%mod;
28     return ans;
29 }
30 int main()
31 {
32     int n,a,b,c,ans,mod=29;
33     while(cin>>n,n)
34     {
35         a=kpow(2,2*n+1,mod)-1;
36         b=(kpow(3,n+1,mod)-1)*15%29;
37         c=(kpow(22,n+1,mod)-1)*18%29;
38         ans=a*b*c%29;
39         cout<<ans<<endl;
40     }
41 }

 

 

转载于:https://www.cnblogs.com/qijinbiao/archive/2012/07/27/2612147.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值