Problem Descriptionconsider A positive integer x,and let S is the sum of all positive integer divisors of 2004^x. Your job is to determine s modulo (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,, 167, 334, 501, 668, 1002 and 2004. Therefore s = 4704 and s modulo are equal to 6.
Inputthe input consists of several test cases. Each test case is contains a line with the integer x (1 <= x <= 10000000).
A test Case of X = 0 indicates the end of input, and should not being processed.
Outputfor each test case, in a separate line, please output the result of S modulo 29.
Sample Input1100000
Sample Output610
Test instructions: Find the value of 2014^x%29.
Fast power and modulus multiplication inverse element. Multiply inverse: x= (1/b)%m. Find the value of x. X*b=k*m+1, which is k to the minimum positive integer, x is also an integer. That B can be divisible by k*m+1.
1#include <cstdio>2#include <cstring>3 using namespacestd;4 intF1 (intXinty)5 {6 intans=1;7 while(y)8 {9 if(y&1) ans=ans*x% in;Tenx=x*x% in; Oney>>=1; A } - returnans; - } the intF2 (intx) - { - intI=1; - while(i) + { - if(( in*i+1)%x==0) Break; +i++; A } at return( in*i+1)/x; - } - intMain () - { - intx,a,b,c; - while(~SCANF ("%d",&x)) in { - if(!x) Break; toA= (F1 (2,2*x+1)-1)% in; +C= (((F1 (3, x+1)-1)% in) *f2 (2))% in; -B= (((F1 ( A, x+1)-1)% in) *f2 ( +))% in; theprintf"%d\n", (a*b*c)% in); * } $ return 0;Panax Notoginseng}
HDU 1452 Happy 2004 (Fast Power + modulo multiplication inverse)