Cod sursa(job #1143638)

Utilizator atatomirTatomir Alex atatomir Data 15 martie 2014 19:51:32
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.49 kb
const modd = 1999999973;
var n,k:int64;

function poww(n,k:int64):int64;
begin
  if k = 0 then poww := 0 else
  if k = 1 then poww := n else
  begin
    if k mod 2 = 1 then
      poww := (n*poww((n*n)mod modd,k div 2))mod modd
    else
      poww :=   (poww((n*n)mod modd,k div 2))mod modd;
  end;
end;

begin
  assign(input,'lgput.in'); reset(input);
  assign(output,'lgput.out'); rewrite(output);

  readln(n,k);
  writeln(poww(n,k));

  close(input);
  close(output);
end.