begin repeat var a,b,c,r:comp=1;read(a,b,c);repeat if 1and b>0then r:=r*a mod c;a:=a*a mod c;shr(b,1)until b=0;writeln(r)until 1=0end.