POJ 1845 Sumdiv
2017-12-30 19:58
211 查看
escription
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=p1^c1*p2^c2*p2^c3
所有因数和=(1+p1^1+....p1^c1)*(1+p2^1+....p2^c2)*(1+p3^1+...p3^c3)
等比数列求和
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=p1^c1*p2^c2*p2^c3
所有因数和=(1+p1^1+....p1^c1)*(1+p2^1+....p2^c2)*(1+p3^1+...p3^c3)
等比数列求和
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; typedef long long lol; lol Mod=9901,A,B,lim,ans; lol pri[10001],cnt[10001],tot; lol qpow(lol x,lol y) { lol res=1; while (y) { if (y&1) res=(res*x)%Mod; x=(x*x)%Mod; y/=2; } return res; } lol get_sum(lol x,lol y) { if (y==0) return 1; if (y%2) return ((qpow(x,y/2+1)+1)*get_sum(x,y/2))%Mod; else return ((qpow(x,y/2+1)+1)*get_sum(x,y/2-1)+qpow(x,y/2))%Mod; } int main() {lol i,s; cin>>A>>B; lim=sqrt(A); for (i=2;i<=lim;i++) if (A%i==0) { s=0; while (A%i==0) { s++; A/=i; } pri[++tot]=i; cnt[tot]=s*B; } if (A!=1) { pri[++tot]=A; cnt[tot]=B; } ans=1; for (i=1;i<=tot;i++) { ans=(ans*get_sum(pri[i],cnt[i]))%Mod; } cout<<ans; }
相关文章推荐
- poj 1845Sumdiv(唯一分解定理&&约数和公式&&二分求等比数列和&&反复平方法计算p^n幂~~~好多定理啊)
- poj 1845 Sumdiv
- POJ 1845 Sumdiv(逆元)
- 【POJ 1845】 Sumdiv (整数唯分+约数和公式+二分等比数列前n项和+同余)
- poj 1845 Sumdiv——数论
- poj1845-Sumdiv
- Sumdiv POJ - 1845 (数论)
- POJ 1845 Sumdiv(逆元的应用)
- poj 1845 Sumdiv(分治+快速幂)
- POJ-1845-Sumdiv 等比数列求和/数学/(二分法/逆元法/变换取模法)
- poj1845 Sumdiv(数论,因数和,等比数列,快速幂)
- POJ 1845 --Sumdiv 约数基本定理+乘法逆元
- POJ 1845 Sumdiv (因子和)
- poj1845 Sumdiv
- POJ 1845 Sumdiv(因子分解+快速幂+二分求和)
- POJ 1845 Sumdiv
- POJ 1845 Sumdiv
- POJ 1845 Sumdiv (因子和)
- Sumdiv(poj 1845)
- poj-1845 Sumdiv (逆元+费马小定理+因子和)