Cod sursa(job #1386611)
| Utilizator | Data | 13 martie 2015 09:19:07 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | fpc | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
program putere;
const c=1999999973;
var x,n:qword;
f,g:text;
function putere(x,n:qword):qword;
var aux:qword;
begin
if n=0 then putere:=1
else if n=1 then putere:=x
else if n mod 2 = 1 then
putere:=(x mod c*(putere(x,n-1) mod c)) mod c
else begin
aux:=putere(x,n div 2) mod c;
putere:=(aux mod c) * (aux mod c) mod c
end
end;
begin
assign(f,'lgput.in'); reset(f);
assign(g,'lgput.out'); rewrite(g);
readln(f,x,n);
writeln(g,putere(x,n)mod c);
close(f); close(g);
end.
