#2094: WRONG ANS?


breezest (Breezest)

學校 : 迦密柏雨中學
編號 : 6924
來源 : [210.3.50.94]
最後登入時間 :
2010-08-13 14:27:58
d219. 00374 - Big Mod -- UVa374 | From: [203.218.17.2] | 發表日期 : 2009-06-23 16:31

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 成功遞交......

 
ZeroJudge Forum