Cod sursa(job #876417)
Utilizator | Data | 11 februarie 2013 20:15:04 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
var n,p,x:int64;c:integer;f,g:text;
const a=1999999973;
Begin
assign(f,'lgput.in');reset(f);
assign(g,'lgput.out');rewrite(g);
readln(f,n,p);
x:=1;
while p<>1 do
Begin
If (p mod 2 = 0) then
Begin
n:=(n*n)mod a;
p:=p div 2;
end
else
Begin
x:=(x*n)mod a;
p:=p-1;
end;
end;
writeln(g,(x*n) mod a);
close(f);
close(g);
end.