Cod sursa(job #876582)
Utilizator | Rares Cheseli rares96cheseli | Data | 11 februarie 2013 22:03:03 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
program putere_in_timp_logaritmic;
var n,p,x:qword;
f,g:text;
begin
assign(f,'lgput.in');reset(f);
assign(g,'lgput.out');rewrite(g);
read(f,n,p);
x:=1;
while p<>1 do
begin
if (p mod 2=0)then begin
n:=(n*n) mod 1999999973;
p:=p div 2;
end
else begin
x:=(x*n) mod 1999999973;
dec(p);
end;
end;
writeln(g,(x*n)mod 1999999973);
close(f); close(g);
end.