Cod sursa(job #146662)
Utilizator | Data | 1 martie 2008 23:01:59 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
const m=1999999973;
var a,b:int64;
f:text;
function putere(b:int64):int64;
var nr:int64;
begin
if b=1 then putere:=a mod m
else
begin
nr:=putere(b shr 1) mod m;
if not odd(b) then putere:=(nr*nr) mod m
else putere:=(nr*nr*a) mod m;
end;
end;
begin
assign(f,'lgput.in');
reset(f);
read(f,a,b);
close(f);
assign(f,'lgput.out');
rewrite(f);
write(f,putere(b));
close(f);
end.