poj 1845
2015-09-26 16:48
239 查看
Sumdiv
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
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).
Source
Romania OI 2002
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 16666 | Accepted: 4164 |
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
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 10005 int 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 50000000 0 0 1 0 2 0 2 1 2 2 3 0 3 1 3 2 3 3 4 5 5 8 */
相关文章推荐
- socket详解及简易聊天室编写
- C++套接字编程(聊天程序)
- 在Myeclipse中移除项目对Hibernate的支持
- 对比synchronized与java.util.concurrent.locks.Lock 的异同
- Cocos2d-x 周边工具 之 TexturePacker
- 结构体数组
- HTML如何在图片上添加内容(如文字,菜单栏,按钮等)
- linux JDK 安装无法建立连接的问题解决 wget方法后面再说
- centos7下面搭建lnmp环境
- 中国大学MOOC-陈越、何钦铭-数据结构-2015秋 03-树3 Tree Traversals Again (25分)
- iOS开发:UIWebView
- Python包管理pip工具在Mac OSX10.10上的安装及lxml安装错误的解决办法
- Android开发日志问题
- 设计思想
- tonado框架的列表嵌套 (template中for循环嵌套)
- Android项目实战-云词典
- 智慧银行不再“面对面”它比ATM聪明 它叫VTM
- 占用CPU时间,调用函数,点亮LED的C语言程序 【原创】
- Android项目源码运行不起来的七种解决方法
- Maven pom.xml加载不同properties配置