HDU 1452 Happy 2004(约数和定理)
来源:互联网 发布:限制文件夹大小 linux 编辑:程序博客网 时间:2024/05/22 07:56
Happy 2004
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1904 Accepted Submission(s): 1394
Problem Description
Consider a positive integer X,and let S be the sum of all positive integer divisors of 2004^X. Your job is to determine S modulo 29 (the rest of the division of S by 29).
Take X = 1 for an example. The positive integer divisors of 2004^1 are 1, 2, 3, 4, 6, 12, 167, 334, 501, 668, 1002 and 2004. Therefore S = 4704 and S modulo 29 is equal to 6.
Take X = 1 for an example. The positive integer divisors of 2004^1 are 1, 2, 3, 4, 6, 12, 167, 334, 501, 668, 1002 and 2004. Therefore S = 4704 and S modulo 29 is equal to 6.
Input
The input consists of several test cases. Each test case contains a line with the integer X (1 <= X <= 10000000).
A test case of X = 0 indicates the end of input, and should not be processed.
A test case of X = 0 indicates the end of input, and should not be processed.
Output
For each test case, in a separate line, please output the result of S modulo 29.
Sample Input
1100000
Sample Output
610
Source
ACM暑期集训队练习赛(六)
POINT:
了解一下约数和定理就行,用一下费马求逆元。
#include <iostream>#include <stdio.h>using namespace std;#define LL long longconst int p = 29;int qkm(int base,int mi){ base%=p; int ans=1; while(mi) { if(mi&1) (ans*=base)%=p; (base*=base)%=p; mi>>=1; } return ans;}int main(){ int x; while(~scanf("%d",&x)&&x) { int a=qkm(2,2*x+1)-1; int b=((qkm(3,x+1)-1)+p)%p*qkm(2,p-2); int c=((qkm(167,x+1)-1)+p)%p*qkm(166,p-2); printf("%d\n",a*b*c%p); } }
阅读全文
0 0
- HDU 1452 Happy 2004(约数和定理)
- 【原创】【数论】HDU-1452 Happy 2004(约数和定理)
- hdu-1452(约数和定理+求逆元)
- HDU 1452 Happy 2004(唯一分解定理)
- HDU-1452 Happy 2004(逆元+因子和+费马定理)
- HDU 1452 Happy 2004 (唯一分解定理 + 求等比数列前n项和)
- 约数个数定理 和 约数和定理
- 约数个数定理and约数和定理
- poj1845Sumdiv+约数和定理
- 约数和定理
- hdu 1492 约数个数定理
- 数论 约数定理 约数和定理 欧拉定理
- 约数定理(约数个数定理,约束和定理)
- HDU 1452 Happy 2004(因子和)
- hdu 1452 Happy 2004 因子和
- HDU 1452 Happy 2004 (因子和)
- hdu 1452 Happy 2004
- HDU 1452 Happy 2004
- 选择排序和冒泡排序
- 数据库三大范式、pl/sql语法格式
- 数据库SQL之DDL语句的使用
- (转)基于哈夫曼(haffuman)算法的文件压缩的实现(C语言)
- Redis集群搭建与简单使用
- HDU 1452 Happy 2004(约数和定理)
- floyd算法 (算每两点间的距离)
- 计算几何模版
- jquery_selector01
- Unity3D Shader(17)——水的折射
- 【CodeForces
- Docker 镜像的存储机制
- NYOJ-0058-最少步数
- 猪八戒笔试:数串