Cod sursa(job #146293)
| Utilizator | Data | 1 martie 2008 15:21:33 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | fpc | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
var fi,fo:text;
n,p,m:int64;
function exp(p:int64):int64;
var aux:int64;
begin
if p=0 then exp:=1
else
begin
aux:=exp(p shr 1) mod m;
aux:=(aux*aux)mod m;
if p and 1=1 then exp:=(aux*n) mod m
else exp:=aux;
end;
end;
begin
assign(fi,'lgput.in'); reset(fi);
assign(fo,'lgput.out'); rewrite(fo);
read(fi,n,p);
m:=1999999973;
n:=n mod m;
writeln(fo,exp(p));
close(fi);
close(fo);
end.