POJ 1845Sumdiv(数论)
2017-01-14 09:21
483 查看
Sumdiv
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 20041 | Accepted: 5060 |
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).
Source
膜拜大神 http://blog.csdn.net/rowanhaoa/article/details/8591077
#include <iostream> #include <stdio.h> #include <string.h> #include <math.h> using namespace std; long long p[100000]; long long k[100000]; long long pows(long long n, long long m)//快速幂 { long long t = 1; while(m) { if(m%2 != 0) { t = (t*n)%9901; m--; } n = (n*n)%9901; m /= 2; } //cout<<t<<endl; return t; } long long mou(long long x,long long y) { if(y==0) return 1; if(y%2==0) return (((mou(x,y/2-1)%9901)*((1+pows(x,y/2+1))%9901))%9901+pows(x,y/2)%9901)%9901; if(y%2!=0) return (mou(x,y/2)%9901)*((1+pows(x,y/2+1))%9901)%9901; } int main() { long long m, n, i; while(~scanf("%lld %lld", &n, &m)) { int j = 0; for(i = 2; i <= (int)sqrt(n*1.0); i += 2) { if(n%i==0) { p[j] = i; k[j] = 0; while(n%i==0) { k[j]++; n /= i; } } j++; if(i == 2) { i--; } if(n==1) { break; } } if(n != 1) { p[j] = n; k[j++] = 1; } //以上是分解质因数。 for(i = 0; i < j; i++) { //printf("%d %d\n", p[i], k[i]); k[i] *= m; } long long sum = 1; for(i = 0; i < j; i++) { sum = sum * mou(p[i], k[i])%9901; } printf("%lld\n", sum); } return 0; }
相关文章推荐
- POJ 1845 Sumdiv 简单数论问题
- poj 1845 Sumdiv 数论
- poj1845——Sumdiv(数论+幂的因子和)
- 【数论】【poj1845】Sumdiv
- poj 1845 Sumdiv(数论:欧拉函数+二分求等比数列前n项和+快速幂取模)
- poj 1845 Sumdiv 数论--等比数列和(逆元或者递归)
- 【数论】POJ_1845_Sumdiv
- [POJ1845]Sumdiv(数论+矩乘)
- POJ 1845 Sumdiv (数论,约数和)
- POJ 1845-Sumdiv(数论,A^B的所有约数和)
- poj 1845 Sumdiv (很多数论知识 ,很经典 )
- poj 1845 Sumdiv (数论)
- Sumdiv POJ - 1845 (数论)
- poj1845 Sumdiv(数论,因数和,等比数列,快速幂)
- POJ 1845-Sumdiv 数论 +快速幂&&筛素&&分解质因数&&求因数之和的模板
- [poj1845] Sumdiv(数论,质因数分解,约数和,快速幂)
- (Relax 数论1.23)POJ 1845 Sumdiv(求A^B的约数之和)
- poj 1845 Sumdiv (数论)
- POJ 1845 Sumdiv(数论,求A^B的所有约数和)
- poj1845--Sumdiv(数论篇3--真滴是数论啊。。。。)