POJ 1845 Sumdiv(逆元)
2015-07-11 12:44
393 查看
Description
Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S modulo 9901 (the rest of the division of S by 9901).
Input
The only line contains the two natural numbers A and B, (0 <= A,B <= 50000000)separated by blanks.
Output
The only line of the output will contain S modulo 9901.
Sample Input
Sample Output
Hint
2^3 = 8.
The natural divisors of 8 are: 1,2,4,8. Their sum is 15.
15 modulo 9901 is 15 (that should be output).
题意:求A^B的所有约数和
题解:根据唯一分解定理:A=p1^a1*p2*a2.....那么A^B=(p1^(a1*B)*p2^(a2*B).....
那么对于求和操作来说sum=(1+p1+p1^2...p1^(a1*B)(1+p2............
所以就是等比数列求和,那么sum=(pi^(ai*B+1)-1)/(pi-1)%mod;
那么a/b%mod=a%(b*mod)/b;
Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S modulo 9901 (the rest of the division of S by 9901).
Input
The only line contains the two natural numbers A and B, (0 <= A,B <= 50000000)separated by blanks.
Output
The only line of the output will contain S modulo 9901.
Sample Input
2 3
Sample Output
15
Hint
2^3 = 8.
The natural divisors of 8 are: 1,2,4,8. Their sum is 15.
15 modulo 9901 is 15 (that should be output).
题意:求A^B的所有约数和
题解:根据唯一分解定理:A=p1^a1*p2*a2.....那么A^B=(p1^(a1*B)*p2^(a2*B).....
那么对于求和操作来说sum=(1+p1+p1^2...p1^(a1*B)(1+p2............
所以就是等比数列求和,那么sum=(pi^(ai*B+1)-1)/(pi-1)%mod;
那么a/b%mod=a%(b*mod)/b;
#include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<string> #include<iostream> #include<queue> #include<cmath> #include<map> #include<stack> #include<set> using namespace std; #define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i ) #define REP( i , n ) for ( int i = 0 ; i < n ; ++ i ) #define CLEAR( a , x ) memset ( a , x , sizeof a ) const int INF=0x3f3f3f3f; typedef long long LL; const int maxn=10010; const LL mod=9901; LL A,B; int prim[maxn+10]; int vis[maxn+10]; int cnt; void get_prim() { for(int i=2;i*i<=maxn;i++) { if(!vis[i]) for(int j=i*i;j<=maxn;j+=i) vis[j]=1; } for(int i=2;i<=maxn;i++) if(!vis[i]) prim[cnt++]=i; } //A^B%mod LL quick_add(LL a,LL b,LL MOD) { LL ans=0; while(b) { if(b&1) ans=(ans+a)%MOD; b>>=1; a=(a+a)%MOD; } return ans; } LL quick_mod(LL a,LL b,LL MOD) { LL ans=1; while(b) { if(b&1) ans=quick_add(ans,a,MOD); b>>=1; a=quick_add(a,a,MOD); } return ans; } void solve() { LL ans=1; for(int i=0;i<cnt&&prim[i]*prim[i]<=A;i++) { if(A%prim[i]==0) { int num=0; while(A%prim[i]==0) { A/=prim[i]; num++; } LL MOD=(prim[i]-1)*mod; ans*=(quick_mod(prim[i],num*B+1,MOD)-1+MOD)/(prim[i]-1); ans%=mod; } } if(A>1) { LL MOD=(A-1)*mod; ans*=(quick_mod(A,B+1,MOD)-1+MOD)/(A-1); ans%=mod; } printf("%I64d\n",ans); } int main() { get_prim(); while(~scanf("%I64d%I64d",&A,&B)) solve(); return 0; }
相关文章推荐
- iOS--NSNumber,NSDate,NSValue
- 正确 zip 压缩和解压码
- 科目二终于过了(各项目总结)
- ClearCase 中rmname 的描述
- 操作系统概念学习笔记 1 加电引导过程
- css中position属性(absolute|relative|static|fixed)概述及应用
- Servlet 3.1 新特性示例
- UI2_ButtonChess
- Linux命令行下载文件百度云盘
- MVC项目中验证码的使用
- iphone开发中,委托、代理、协议、数据源等几个重要概念
- Android真机连接本地服务器(同一局域网)
- 开源框架Android-Query 实现https自签名ssl证书验证
- java内部类
- iOS--NSDictionary
- Linux Shell 数字计算与比较
- 这两天阅读频谱仪与锁相放大器资料小结
- 自动化运维那点事
- c++ 单利
- Android HandlerThread 源码分析