欧拉定理之运用,
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int mod1(int x)
{
int a=1,b=1,c=1,r;
for(int i=0;i<=x;++i)
{
a=a*(i?4:2)%29; //表示2^(2*x+1)
b=b*3%29; //3^(x+1)
c=c*22%29; //167^(x+1)
}
r=(a-1)*(b-1)*(c-1)%29; //s=r/332,
return 9*r%29; //s%29=r*9%29;
}
int main()
{
int x;
while(scanf("%d",&x),x)
printf("%d\n",mod1(x%28));
return 0;
}