Cod sursa(job #935881)

Utilizator Andru_Andru Felipe Zuniga Andru_ Data 4 aprilie 2013 23:49:56
Problema Factorial Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.61 kb
program fact;
var
 vector:array[0..12] of longint= (1, 6, 31, 156, 781, 3906, 19531, 97656, 488281, 2441406, 12207031, 61035156, 1000000001);
 p,zerouri:longint;
 marime,i:byte;
 fin,fout:text;
begin
 assign(fin,'fact.in');
 reset(fin);
 read(fin,p);
 close(fin);
 marime:=0;
 while p>vector[marime] do
  marime:=marime+1;
 zerouri:=p;
 for i:=marime downto 1 do
  begin
   zerouri:=zerouri-p div vector[i];
   if p mod vector[i]>=vector[i]-i then
    p:=-1;
  end;
 assign(fout,'fact.out');
 rewrite(fout);
 if p=0 then
  write(fout,1)
 else
  if p=-1 then
   write(fout,-1)
  else
   write(fout,zerouri*5);
 close(fout);
end.