#include <stdio.h>unsignedlongbigmod(unsignedlongb, unsignedlongp, unsignedlongm);
unsignedlongsquare(unsignedlonga);
intmain()
{
unsignedlongb, p, m, res;
#ifndef ONLINE_JUDGEfreopen("d:\\uva_in.txt", "r", stdin);
#endifwhile (scanf("%lu%lu%lu", &b, &p, &m) ==3) {
res=bigmod(b, p, m);
printf("%lu\n", res);
}
return0;
}
unsignedlongbigmod(unsignedlongb, unsignedlongp, unsignedlongm)
{
if (p==0)
return1;
elseif (p%2==0)
returnsquare(bigmod(b, p/2, m)) %m;
elsereturn (b%m) *bigmod(b, p-1, m) %m;
}
unsignedlongsquare(unsignedlonga)
{
returna*a;
}