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).
Input The input consists of several test cases. Each test case contains a line with the integer X (1 <= X <= 10000000).
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 | We have carefully selected several similar problems for you: 1695 1573 1788 1060 1370
|
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int quick_mod(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(scanf("%d",&X), X )
{
a = quick_mod( 2, 2 * X + 1 );
b = quick_mod( 3, ( X + 1 ) );
c = quick_mod( 22, ( X + 1 ) );
printf("%d\n",( a - 1 ) * (( b - 1 ) * 15) * ( c - 1 ) * 18 % 29) ;
}
return 0;
}