Fork me on GitHub

 

#include<iostream>
#include<cstdio>
#include<algorithm>
#define max(a,b) ((a)>(b)?(a):(b))
int qpow(int a,int b)
{
    __int64 res=1;
   while(b)
   {
       if(b&1) { res*=a;res%=29;}
       a*=a;a%=29;b>>=1;
   }
   return (int)res;
}
int main()
{
//    freopen("in.txt","r",stdin);
    int i,j,n,sum;
    while(scanf("%d",&n)&&n)
    { 
        sum=(qpow(2,2*n+1)-1);
        sum*=((qpow(3,n+1)-1)*15);
        sum*=((qpow(22,n+1)-1)*18);
        sum%=29;
         printf("%d\n",sum);  
    }
    return 0;
}
给你一个X求2004的X次幂的所有因子之和。  首先我们可以把2004=2^2*3*167,有一下几种组合
2^0*3^0*167^0= 1*1*1=1;                  由左边的组合可以得出:
2^1*3^0*167^0= 2*1*1=2;                  2^2有3种情况:1, 2, 4;     
2^0*3^1*167^0= 1*3*1=3;                  3^1有3种情况:1, 3;
2^2*3^0*167^0= 4*1*1=4;                  167^1有3种情况:1, 167;
2^1*3^1*167^0= 1*3*1=6;                  把左边的因子加和可以得出
2^2*3^1*167^0= 4*3*1=12;                (1+2+4)*(1+3)*(1+167)=4704;
2^0*3^0*167^1= 1*1*167=167;              sum(2004^x)=sum(2^(2*x))*sum(3^x)*sum(167^x)
2^1*3^0*167^1= 2*1*167=334;              sum(a^b)=1+a+a^2+a^3+..+a^b=(a^(b+1)-1)/(a-1)
2^0*3^1*167^1= 1*1*501=501;              a=sum(2^(2*x)); b=sum(3^x); c=sum(167^x);
2^2*3^0*167^1= 4*1*167=668;              sum(2004^x)=a*b*c);
2^1*3^1*167^1= 2*3*167=1002;            
2^2*3^1*167^1= 2*3*167=2004;
 
因为X输入值很大 所以得用快速a^b%n
sum(a^b)=(a^(b+1)-1)/(a-1)))=(a^(b+1)-1)*(a-1)^(-1));
x^-1对29取模那么得求出x^-1的逆元http://wenku.baidu.com/view/f0894659be23482fb4da4c51.html

 

 

 

一夏 吕(992463596) 11:56:18
有人懂逆元吗
一夏 吕(992463596) 11:56:30
用扩展欧几里得算法 怎么求辗转相除以后不是1的情况呀 大神跪求指导
[ECJTU]一毛(332770741) 11:57:25
互质才有逆元
一夏 吕(992463596) 11:58:00
嗯 比如22和29
一夏 吕(992463596) 11:58:21
21和29
一夏 吕(992463596) 11:58:35
29=21+8 21=8*2+5
一夏 吕(992463596) 11:58:53
这里是5 不是1 所以是不是还要继续推。。
一夏 吕(992463596) 11:59:16
1=21*b+29*k 要求b
[ECJTU]一毛(332770741) 12:00:15
。。。extend_gcd()可以求出某个特解
一夏 吕(992463596) 12:00:53
答案是18
一夏 吕(992463596) 12:00:57
但我不知道怎么求
[ECJTU]一毛(332770741) 12:01:04
我也不会
一夏 吕(992463596) 12:02:18
5b+7k=1
一夏 吕(992463596) 12:02:29
7=5+2 5=2*2+1
一夏 吕(992463596) 12:02:56
1=5-2*(7-5)=5*3-2*7 b=3 就这么求
一夏 吕(992463596) 12:06:46
我知道怎么求了
一夏 吕(992463596) 12:06:54
暴搜!

Happy 2004

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 707    Accepted Submission(s): 497


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
 

 

Recommend
lcy
 

 

Statistic | Submit | Discuss | Note
posted on 2013-02-06 13:20  huashiyiqike  阅读(207)  评论(0编辑  收藏  举报