Cod sursa(job #345856)
| Utilizator | Data | 5 septembrie 2009 09:21:35 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | fpc | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
Program lgput;
var f,g:text; n,p:longint;
function putere (x,y:longint):int64;
begin
if y=0 then putere:=1 else
if y=1 then putere:=x else
putere:=((sqr (putere (x,y div 2) mod 1999999973) mod 1999999973)*putere (x,y-2*(y div 2))) mod 1999999973;
end;
begin
assign (f,'lgput.in'); reset (f);
assign (g,'lgput.out'); rewrite (g);
readln (f,n,p);
writeln (g,putere (n mod 1999999973,p));
close (f); close (g);
end.