Cod sursa(job #234872)
| Utilizator | Data | 22 decembrie 2008 09:54:19 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 20 |
| Compilator | fpc | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
const m=1999999973;
var n,p:int64;
f,g:text;
function putere(x,n:integer):int64;
begin
if n=0 then putere:=1
else if n mod 2=0 then putere:=((putere(x,n div 2)) mod m)*((putere(x,n div 2)) mod m)
else putere:=((putere(x,n-1))mod m)*(x mod m);
end;
begin
assign(f,'lgput.in');
reset(f);
readln(f,n,p);
close(f);
assign(g,'lgput.out');
rewrite(g);
writeln(g,putere(n,p) mod m);
close(g);
end.
