Cod sursa(job #1374361)
| Utilizator | Data | 5 martie 2015 08:33:57 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | fpc | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
program ridicare_la_putere;
const k=1999999973;
var n,p,x:int64;
f,g:text;
procedure pow(p:longint);
begin
if p<>0 then
begin
if p mod 2<>0 then
begin
x:=((x mod k)*(n mod k)) mod k;
pow(p-1);
end
else
begin
n:=((n mod k)*(n mod k)) mod k;
pow(p div 2);
end;
end;
end;
begin
assign(f,'lgput.in'); reset(f);
assign(g,'lgput.out'); rewrite(g);
readln(f,n,p);
x:=1;
pow(p);
writeln(g,x);
close(f);
close(g);
end.
