Cod sursa(job #872925)
Utilizator | Data | 6 februarie 2013 18:56:11 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 0.34 kb |
var n,p,x:longint;f,g:text;
const a:longint=19973;
Begin
assign(f,'lgput.in');reset(f);
assign(g,'lgput.out');rewrite(g);
readln(f,n,p);
x:=n;
while p>1 do
If p mod 2 = 0 then
Begin
x:=(x*x) mod a;p:=p div 2;
end
else
Begin
x:=(x*n) mod a;p:=p div 2;end;
writeln(g,x);
close(f);
close(g);
end.