Cod sursa(job #731152)

Utilizator ZancrowAugustin Zancrow Data 7 aprilie 2012 16:50:42
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.5 kb
var n,p:int64;
     f,h:text;

Function rest(q:int64):int64;
var t:int64;
begin
if q=1 then rest:=(n mod 1999999973) else
             if odd(q) then rest:=((rest(q-1)*n) mod 1999999973)
             else begin
                t:=rest(q div 2) mod 1999999973;
                t:=t*t;
                rest:=t mod 1999999973;
             end;
end;

begin
assign(f,'lgput.in');
reset(f);
read(f,n);
readln(f,p);
assign(h,'lgput.out');
rewrite(h);
writeln(h,rest(p));
close(f);
close(h);
end.