Cod sursa(job #282831)
| Utilizator | Data | 18 martie 2009 12:55:10 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
| Compilator | fpc | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
const ct=1999999973;
var x,p:int64;
f:text;
function putere(n:int64):int64;
var jumate:int64;
begin
if n=0 then
putere:=1
else
if n mod 2=0 then
begin
jumate:=putere(n div 2) mod ct;
putere:=(jumate*jumate) mod ct;
end
else
begin
jumate:=putere(n div 2) mod ct;
putere:=(x*jumate*jumate) mod ct;
end;
end;
begin
assign(f,'lgput.in'); reset(f);
readln(f,x,p);
close(f);
assign(f,'lgput.out'); rewrite(f);
writeln(f,putere(p));
close(f);
end.