const divnum = 3;
var B,P,M : longint;
function arithmetic(iB,iP,iM:longint):longint;
var tempari, tempmod,i :longint;
begin
arithmetic := 1;
if iP > divnum then
begin
for i := 1 to (iP mod divnum) do
arithmetic := (arithmetic * (iB mod iM)) mod iM;
tempmod := iP div divnum;
tempari := arithmetic(iB, tempmod, iM);
for i := 1 to divnum do
arithmetic := (arithmetic*tempari) mod iM;
end
else
if iP <> 0 then
for i := 1 to iP do
arithmetic := (arithmetic * (iB mod iM)) mod iM
else arithmetic := 1 mod iM;
end;
begin
while not eof do
begin
readln(B);
readln(P);
readln(M);
writeln(arithmetic((B mod M),P,M));
end;
end.
-------------------------------
我在UVa Online Judge 成功遞交......