快速幂O(log₂N)var b,p,k,ans:int64;PRocedure ksm(x:int64);begin if x=1 then exit; if x mod 2=0 then begin ksm(x div 2);ans:=ans*ans mod k;end else begin ksm(x div 2);ans:=ans*ans mod k*b mod k;end;end;begin readln(b,p,k); ans:=b; ksm(p); writeln(b,'^',p,' mod ',k,'=',ans mod k);end.