int binary[50];
int bin(int x)
{
int i;
for(i=0;;i++)
{
binary[i]=x%2;
x=x/2; if(x==0) break;
}
return i;
}
int main()
{
int i,j,n,b,p,m,x;
while(scanf("%d%d%d",&b,&p,&m)==3)
{
x=1; n=b%m; j=bin(p);
for(i=0;i<=j;i++)
{
if(binary[i] == 1) x=(x*n)%m;
n=(n*n)%m;
}
printf("%d\n",x);
}
return 0;
}
/*
Input:
3
18132
17
17
1765
3
2374859
3029382
36123
Output:
13
2
13195
*/
No comments:
Post a Comment