Cod sursa(job #199662)

Utilizator 05_YohnE1 La5c01 05_Yohn Data 19 iulie 2008 23:33:37
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator fpc Status done
Runda Arhiva educationala Marime 0.71 kb
program gaju;
var x,y:longint;
    f,g:text;
function p(x,y:longint):longint;
var aux:longint;
begin
if y<>1 then begin
            if y mod 2=0 then
                         begin
                         aux:=p(x,y div 2) mod 1999999973 ;
                         p:=(aux*aux) mod 1999999973;
                         end
                         else begin
                         aux:=p(x,y-1) mod 1999999973;
                         p:=(aux*x) mod 1999999973;
                         end;
            end
            else p:=x;
end;
begin
assign(f,'lgput.in');reset(f);
assign(g,'lgput.out');rewrite(g);
readln(f,x,y);
if y<>0 then writeln(g,p(x,y))
        else writeln(g,1);
close(g);
end.