Cod sursa(job #152409)

Utilizator belgun_adrianBelgun Dimitri Adrian belgun_adrian Data 9 martie 2008 14:05:44
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator fpc Status done
Runda Arhiva educationala Marime 0.76 kb
var n,p:longword;

const mare=1999999973;

procedure citire;
        var f:text;
        begin
        assign(f,'lgput.in');
         reset(f);
         readln(f,n,p);
         close(f);
        end;

procedure scrie(k:longword);
        var f:text;
        begin
        assign(f,'lgput.out');
         rewrite(f);
         writeln(f,k);
         close(f);
        end;

function put(k,x:longint):longword;
        var t:longword;
        begin
        if x=1 then
           put:=k mod mare
        else
           begin
           t:=put(k,x div 2);
           if x mod 2 =0 then
              put:=t*t mod mare
           else
              put:=t*t*put(k,1) mod mare;
           end;

        end;

begin
citire;
scrie(put(n,p));
end.