Cod sursa(job #1414422)

Utilizator ButnaruButnaru George Butnaru Data 2 aprilie 2015 16:40:29
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.38 kb
program expo;
const modd=1999999973;
var p,x,sol:int64;
    f1,f2:text;
begin
assign (f1,'lgput.in');
assign (f2,'lgput.out');
reset (f1);
rewrite (f2);
readln (f1,x,p);
sol:=1;
while p>0 do begin
if p mod 2=1 then sol:=(sol mod modd)*(x mod modd) mod modd;
x:=(x mod modd)*(x mod modd) mod modd;
p:=p div 2;
end;
writeln (f2,sol mod modd);
close (f1);
close (f2);
end.