poj 1845
来源:互联网 发布:模拟炒股软件手机版 编辑:程序博客网 时间:2024/06/11 20:18
Sumdiv
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 16666 Accepted: 4164
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
Romania OI 2002
#include <set>#include <cmath>#include <cstdio>#include <cstring>#include <iostream>using namespace std;#define LL long long#define mod 9901#define N 10005int A, B;int mul_pow(int a, int k){ int res = 1; while(k) { if(k & 1) res = (res * a) % mod; a = ((LL)a * a) % mod; k >>= 1; } return res;}set<int> S;void doit(){ S.clear(); int t = A; for(int i = 2; i <= t; i++) while(t != i) { if(t % i == 0) { S.insert(i); t /= i; } else break; } S.insert(t);}int sum(int a, int p){ if(a == 0) return 1; if(p == 0) return 1; if(p & 1) return (1 + mul_pow(a, p / 2 + 1)) * sum(a, p / 2) % mod; else return ((1 + mul_pow(a, p / 2 + 1)) * sum(a, p / 2 - 1) + mul_pow(a, p / 2)) % mod;}int main(){ while(~scanf("%d%d", &A, &B)) { if(A == 1 || A == 0) { printf("1\n"); continue; } doit(); int ans = 1; for(set<int>::iterator it = S.begin(); it != S.end(); it++) { int num = 0; while(A % (*it) == 0) { num++; A /= (*it); } ans = (ans * sum(*it, num * B)) % mod; } printf("%d\n", ans); } return 0;}/*50000000 500000000 01 02 02 12 23 03 13 23 34 55 8*/
0 0
- POJ 1845
- poj 1845
- POJ 1845
- poj 1845
- POJ 1845
- poj 1845
- POJ 1845
- poj 1845
- poj 1845
- poj 1845
- POJ 1845
- Poj - 1845
- poj 1845
- POJ 1845
- POJ 1845 Sumdiv
- poj 1845-Sumdiv
- poj 1845 Sumdiv
- poj 1845 Sumdiv
- linux JDK 安装无法建立连接的问题解决 wget方法后面再说
- 结构体数组
- 请关闭你的“等死模式”
- RDF-资源描述框架
- 在Myeclipse中移除项目对Hibernate的支持
- poj 1845
- Eclipse创建Maven Web工程
- socket详解及简易聊天室编写
- 串
- ios中git的那些事
- Servlet分页技术
- Listview中一些小的注意问题
- c#读取指定路径的配置文件
- OCiOS开发:地图与定位