HDU 1452 欧拉定理的应用+求幂级数的因子和
2014-01-21 21:17
323 查看
点击打开链接
Happy 2004
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 888 Accepted Submission(s): 626
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.
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.
Output
For each test case, in a separate line, please output the result of S modulo 29.
Sample Input
1
10000
0
Sample Output
6
10
Source
ACM暑期集训队练习赛(六)
定理(Fermat)1:如果p是素数,则对任意的a,有
题目要求的是(2004X)的因子和对29取模的结果
求某个数A的所有因子和,首先将该数分解:
,其中p1,p2,...,pn都是素数,则A的任意因子可以表示为:
,其中0<i1<r1.....<in<rn
将其求和,为
如:2004=2^2*3*167,则
而
所以
,其中
X还很大(1<=x<=1000000),根据Fermat定理,任意素数p,任意数a,有
,则
,所以
所以首先将X对28取模,x=X%28是取模的结果,x就很小了(0£x<28,有了这点,输入的X再大也没关系),简单计算就可以得到r的值。
最后,考虑到:
,也即
,k是满足等式的任意整数。
而
所以
例如当X=10000时,计算200410000=220000*310000*16710000的所有因子和对29取模的结果
其
20001%28=9,10001%28=5,167%29=22.
r=(29-1)(35-1)(225-1)%29=18*10*12%29=14
S%29=r*9%29=14*9%29=10, 200410000的所有因子和对29取模的结果是10
//0MS 228K
#include<stdio.h>
int mol29(int x)
{
int f=1,t=1,d=1,r=1;
for(int r=0;r<=x;r++)
{
f=f*(r==x?2:4)%29;//f表示22x+1的值
t=t*3%29; //t表示3x+1的值
d=d*22%29; //d表示167x+1的值
}
r=(f-1)*(t-1)*(d-1)%29;//S=r/332,r的值
return r*9%29;
}
int main()
{
int t;
while(scanf("%d",&t),t)
{
printf("%d\n",mol29(t%28));
}
return 0;
}
相关文章推荐
- 因子和与因子个数的应用:poj 2992+poj 1845+hdu 1452+poj 2480
- HDU 1452 Happy 2004 求2004^n的所有因子和 积性函数应用
- HDU 1452 Happy 2004(因子和)
- HDU 1452 因子和+积性函数+逆元
- hdu 1452 Happy 2004 因子和
- HDU 1452 Happy 2004(因子和的积性函数)
- HDU 1452 Happy 2004 (素因子分解+快速幂模+乘法逆元)
- HDU 1452 Happy 2004 (因子和)
- http://acm.hdu.edu.cn/showproblem.php?pid=1452 因子求和
- hdu 1452 (积性函数+因子和+乘法逆元)
- hdu 1452 因子和 + 逆元素+ 快速幂
- HDU-1452 因子和 积性函数性质
- POJ 1845 Sumdiv 求幂级数的因子和+二分
- hdu 1452(因子和+逆元)
- [数论]HDU 1452 Happy 2004 素因子分解+快速幂模+乘法逆元
- hdu 1452(因子和+积性函数)
- HDU-1452 Happy 2004(逆元+因子和+费马定理)
- hdu 1370 Biorhythms 中国剩余定理的应用 and 枚举方法
- hdu 1452 数论
- hdu 1317 XYZZY【Bellheman_ford 判断正环小应用】