Cod sursa(job #146528)
Utilizator | borsos adrian borsos | Data | 1 martie 2008 20:58:11 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 0.56 kb |
var a,b,c:int64;
f,g:text;
function putere(a,b,c:int64):int64;
var aux:int64;
begin
if b = 1 then putere:=a else
if b mod 2 = 1 then putere:= putere(a,b-1,c)*a mod c else
if b mod 2 = 0 then begin
aux:=putere(a,b div 2,c);
putere:=(aux*aux) mod c;
end;
end;
begin
assign(f,'lgput.in'); reset(f);
assign(g,'lgput.out'); rewrite(g);
readln(f,a,b);
c:=1999999973;
writeln(g,putere(a,b,c));
close(f);
close(g);
end.