Mai intai trebuie sa te autentifici.
Cod sursa(job #1501841)
| Utilizator | Data | 13 octombrie 2015 21:26:11 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | fpc | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
const mod1=1999999973;
var f:text;
a,b,c:longint;
function putere(x,n:longint):longint;
var p:longint;
begin
if n=0 then putere:=1
else
if n mod 2=0 then
begin
p:=putere(x,n div 2);
putere:=(((p)mod mod1)*((p)mod mod1))mod mod1;
end
else
begin
p:=putere(x,(n-1)div 2);
putere:=(((p)mod mod1)*((p)mod mod1)*((x)mod mod1)) mod mod1
end;
end;
begin
assign(f,'lgput.in');
reset(f);
readln(f,a,b);
close(f);
c:=putere(a,b);
assign(f,'lgput.out');
rewrite(f);
writeln(f,c);
close(f);
end.