2013
12-11

# Happy 2004

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.

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.

For each test case, in a separate line, please output the result of S modulo 29.

1
10000
0

6
10

2004^X=4^X * 3^X *167^X
S(2004^X)=S(2^(2X)) * S(3^X) * S(167^X)

167%29 == 22
S(2004^X)=(2^(2X+1)-1) * (3^(X+1)-1)/2 * (22^(X+1)-1)/21

S(2004^X)=(2^(2X+1)-1) * (3^(X+1)-1)/2 * (22^(X+1)-1)/21
=(2^(2X+1)-1) * (3^(X+1)-1)*15 * (22^(X+1)-1)*18

AC code:

#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int _pow( int a, int n )
{
int b = 1;
while( n > 1 )
if( n % 2 == 0 )
{
a = ( a * a ) % 29;
n /= 2;
}
else
{
b = b * a % 29;
n--;
}
return a * b % 29;
}
int main()
{
int X;
int a, b, c;
while( cin >> X, X )
{
a = _pow( 2, 2 * X + 1 );
b = _pow( 3, ( X + 1 ) );
c = _pow( 22, ( X + 1 ) );

cout << ( a - 1 ) * ( b - 1 ) * 15 * ( c - 1 ) * 18 % 29 << endl;
}
return 0;
}

1. Thanks for using the time to examine this, I truly feel strongly about it and enjoy finding out far more on this subject matter. If achievable, as you achieve knowledge