POJ 1845Sumdiv(数论)
来源:互联网 发布:国内论文数据库 编辑:程序博客网 时间:2024/05/17 07:54
Sumdiv
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 20041 Accepted: 5060
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
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).
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;}
0 0
- POJ 1845 Sumdiv(数论)
- POJ 1845Sumdiv(数论)
- poj 1845 Sumdiv (数论)
- poj 1845 Sumdiv 数论
- POJ 1845(Sumdiv) 数论好题
- POJ 1845 Sumdiv (数论,约数和)
- poj 1845 Sumdiv (很多数论知识 ,很经典 )
- POJ 1845 Sumdiv <数论(逆元 / 二分递归)>
- [数论+二分求等比数列]POJ 1845 Sumdiv
- POJ 1845 Sumdiv 简单数论问题
- POJ 1845 Sumdiv(数论+快速幂)
- POJ 1845-Sumdiv(数论,A^B的所有约数和)
- poj-1845-Sumdiv-数论-快速幂取模+快速分解因式
- poj 1845 Sumdiv 数论--等比数列和(逆元或者递归)
- POJ 1845 sumdiv 数论 A^B 的所有约数之和
- POJ Sumdiv (数论+二分等比数列求和)
- poj 1845 Sumdiv (大数幂取模)
- POJ 1845 Sumdiv (因子和)
- 新罕布什尔南方大学Graduation 新罕布什尔南方大学CertifiCate
- Countries in War poj 3114 (有向图的双连通分量+缩点+最短路flyod)
- PHP命名空间(Namespace)的使用详解
- POJ-3268 Silver Cow Party(最短路spfa算法)
- 知道这20个正则表达式,能让你少写1,000行代码
- POJ 1845Sumdiv(数论)
- CodeForces - 757B Bash's Big Day (分解素因子)
- 新罕布什尔大学Graduation 新罕布什尔大学CertifiCate
- 什么是块级元素和内联元素
- Spring XML AOP
- 一个有趣的问题 : α_β_γ_δ_ε_ζ_η_θ_ι_κ_λ_μ_ν怎么读
- 奥尔德森布罗德斯学院Graduation 奥尔德森布罗德斯学院CertifiCate
- ORACLE多表关联UPDATE 语句
- 阿帕拉契圣经学院Graduation 阿帕拉契圣经学院CertifiCate