Cod sursa(job #165727)
Utilizator | Postelnicu Dan Marian kolapsys | Data | 26 martie 2008 18:10:03 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
const c=1999999973;
var n,p,a:longint;
f,g:text;
function rez(x,n:longint):longint;
begin
if n=0 then rez:=1 mod c
else if odd(n) then rez:=(x*rez(sqr(x),(n-1)div 2)) mod c
else rez:=(rez(sqr(x),n div 2)) mod c;
end;
begin
assign(f,'lgput.in'); reset(f);
assign(g,'lgput.out'); rewrite(g);
readln(f,n,p);
a:=rez(n,p);
write(g,a);
close(f);close(g);
end.