Happy 2004
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 920 Accepted Submission (s): 648
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
SOURCEACM Summer Training Team Practice Competition (VI)
1 /*2 Property 1:3 if GCD (A, b) =1 then S (a*b) = S (a) *s (b)4 2004^x=4^x * 3^x *167^x5 s (2004^x) =s (2^ (2X)) * S (3^x) * s (167^x)6 Property 2: If P is a prime number then S (p^x) =1+p+p^2+...+p^x = (p^ (x+1)-1)/(p-1)7 (2^ (2x+1)-1) * (3^ (x+1)-1)/2 * (167^ (x+1)-1)/1668 167%29 =9 S (2004^x) = (2^ (2x+1)-1) * (3^ (x+1)-1)/2 * (22^ (x+1)-1)/166Ten Property 3: (a*b)/C%m= a%m * b%m * INV (c) One where INV (c) satisfies the smallest integer (C*INV (c))%m=1, where m=29 A then INV (1) =1,INV (2) =15,INV (+) =18 - There are: - S (2004^x) = (2^ (2x+1)-1) * (3^ (x+1)-1)/2 * (22^ (x+1)-1)/21 the = (2^ (2x+1)-1) * (3^ (x+1)-1) *15 * (22^ (x+1)-1) *18 - */ - -#include <iostream> +#include <stdio.h> -#include <cstring> +#include <cstdlib> A using namespacestd; at typedef __int64 LL; - - ConstLL p = in; - - ll Pow_mod (ll a,ll N) - { inLL ans=1; - while(n) to { + if(n&1) ans= (ans*a)%p; -N=n>>1; theA= (a*a)%p; * } $ans=ans-1;Panax Notoginseng if(ans<0) ans=ans+p; - returnans; the } + voidSolve (LL x) A { theLL sum=1; +Sum= (Sum*pow_mod (3, x+1)* the)%p; -Sum= (Sum*pow_mod (2,2*x+1))%p; $Sum= (Sum*pow_mod ( A, x+1)* -)%p; $printf"%i64d\n", sum); - } - intMain () the { - LL x;Wuyi while(SCANF ("%i64d", &x) >0) the { - if(x==0) Break; Wu solve (x); - } About return 0; $}