FZU 1053 Happy 2004
2009-07-29 20:20
253 查看
Happy 2004
解题:
运用到欧拉定理,费马小定理。要求某个数A的所有因子和,首先将该数分解:
先贴代码
Time Limit:1s | Memory limit:32M |
Accepted Submit:142 | Total Submit:279 |
Consider a positive integer X,and let S be the sum of all positive integer divisors of 2004X. 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 20041 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 Output for the Sample Input 6 10 Original: 2004 ACM/ICPC Beijing Practice Problem |
运用到欧拉定理,费马小定理。要求某个数A的所有因子和,首先将该数分解:
先贴代码
#include <iostream> using namespace std; int happy(int n) { int r,f,t,d; f=t=d=1; for (r=0;r<=n;++r) { f=f*(r==n?2:4)%29; //f表示2^(2n+1)的值 t=t*3%29; //t表示3^(n+1)的值 d=d*22%29; //d表示167^(n+1)的值 } r=(f-1)*(t-1)*(d-1)%29; //S=r/332,r的值 return r*9%29; //S%29=r*9%29 } int main() { int n; while (cin>>n && n!=0) { cout<<happy(n%28)<<endl; } return 0; }
相关文章推荐
- HDU 1452 Happy 2004(因子和)
- hdu 1452 Happy 2004(积性函数)
- HDU 1452 Happy 2004(因子和的积性函数)
- hdu 1452 Happy2004
- HDU 1452 Happy 2004 (积性函数)
- happy2004
- HDU 1452 Happy 2004
- Happy 2004&&http://acm.hdu.edu.cn/showproblem.php?pid=1452
- hdu1452 Happy 2004 x^y的因子和 逆元 快速乘法
- HDU 1452 Happy 2004
- 【原创】【数论】HDU-1452 Happy 2004(约数和定理)
- HDU-1452 Happy 2004(逆元+因子和+费马定理)
- HDU 1452 Happy 2004 (因子和)
- HDU 1452 Happy 2004
- happy2004
- hdu1452 Happy 2004(规律+因子和+积性函数)
- hdu 1452 Happy 2004 找循环节
- HDU 1452 Happy 2004 求2004^n的所有因子和 积性函数应用
- HDU 1452 Happy 2004(唯一分解定理)
- ACM 数论 HDU 1452 Happy 2004 积性函数