Cod sursa(job #876566)
Utilizator | Rares Cheseli rares96cheseli | Data | 11 februarie 2013 21:46:44 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
program test;
var a:array[1..100] of qword;
x,n,p:qword;
f,g:text;
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 n mod 2=0 then begin
x:=x*n*n;
p:=p div 2;
end
else begin
x:=x*n*n;
dec(p);
p:=p div 2;
end;
end;
writeln(g,x);
close(f); close(g);
end.