Cod sursa(job #359110)

Utilizator ladyLittle Lady lady Data 25 octombrie 2009 19:36:55
Problema Factorial Scor 35
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.45 kb
var p,n,i,x:longint;

function div5(x:longint):byte;
begin
 if (x mod 5<>0) or (x=0) then div5:=0
                          else div5:=div5(x div 5)+1;
end;

begin
assign(input,'fact.in');reset(input);
assign(output,'fact.out');rewrite(output);
 readln(p);
 i:=0;
 n:=0;
repeat
  x:=1;
  inc(i);
  n:=n+x*5;
  if i mod 5=0 then x:=div5(n);
  p:=p-x;
until p<1;
if p<0 then write(-1)
       else write(n);
close(input);close(output);
end.