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