POJ 1845 Sumdiv
2014-11-04 11:23
169 查看
快速幂+等比数列求和。。。。
Sumdiv
DescriptionConsider 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).InputThe only line contains the two natural numbers A and B, (0 <= A,B <= 50000000)separated by blanks.OutputThe only line of the output will contain S modulo 9901.Sample Input2 3Sample Output15Hint2^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).
SourceRomania OI 2002
* This source code was highlighted by YcdoiT. ( style: Codeblocks )
Sumdiv
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 12599 | Accepted: 3057 |
The natural divisors of 8 are: 1,2,4,8. Their sum is 15.
15 modulo 9901 is 15 (that should be output).
SourceRomania OI 2002
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int MOD=9901; typedef long long int LL; int p[10000],n[10000],k,A,B; LL power(LL p,LL n) ///p^n { LL ans=1; while(n>0) { if(n&1) ans=(ans*p)%MOD; n>>=1; p=(p*p)%MOD; } return ans%MOD; } LL Spower(LL p,LL n) ///1+p^1+p^2+p^3+....+p^n-1+p^n { if(n==0) return 1; if(n&1) return ((Spower(p,n/2)%MOD)*((1+power(p,n/2+1))%MOD))%MOD; else return (((Spower(p,n/2-1)%MOD)*(1+power(p,n/2+1))%MOD)%MOD+power(p,n/2)%MOD)%MOD; } int main() { while(scanf("%d%d",&A,&B)!=EOF) { k=0; for(int i=2;i*i<=A;) { if(A%i==0) p[k]=i,n[k]=0,k++; while(A%i==0) { n[k-1]++; A/=i; } if(i==2) i++; else i+=2; } if(A!=1) { p[k]=A; n[k++]=1; } LL ans=1; for(int i=0;i<k;i++) { ans=(ans*Spower(p,B*n[i]))%MOD; } printf("%I64d\n",ans); } return 0; } [/i] |
相关文章推荐
- POJ-1845 Sumdiv 数论
- poj 1845 Sumdiv 素数筛+快速幂求逆元+二分乘法
- (POJ - 1845)Sumdiv(分治法/费马小定理+快速幂)
- POJ 1845-Sumdiv 数论 +快速幂&&筛素&&分解质因数&&求因数之和的模板
- poj 1845 Sumdiv 矩阵法求幂的和
- POJ-1845-Sumdiv 等比数列求和/数学/(二分法/逆元法/变换取模法)
- 【数论】【poj1845】Sumdiv
- POJ 1845 Sumdiv (快速分解因式+快速幂取模)
- poj1845 Sumdiv
- POJ1845:Sumdiv
- poj 1845 POJ 1845 Sumdiv 数学模板
- POJ 1845 Sumdiv
- POJ 1845 Sumdiv(因子分解+快速幂+二分求和)
- POJ 1845 Sumdiv 解题报告(二分 & 逆元)
- poj 1845 Sumdiv [素数筛+母函数]
- POJ1845 Sumdiv(求所有因数和+矩阵快速幂)
- poj 1845 Sumdiv ,质因子分解
- POJ 1845 Sumdiv
- 【POJ 1845】Sumdiv
- POJ 1845 Sumdiv 求某数的幂取模