Cod sursa(job #359167)

Utilizator ladyLittle Lady lady Data 25 octombrie 2009 22:26:51
Problema Factorial Scor 35
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.48 kb
var p,n,i,x:longint;

function div5(x:longint):byte;
var m:byte;
begin
m:=0;
 while x mod 25=0 do begin
  inc(m,2);
  x:=x div 25;
 end;
 if x mod 5=0 then inc(m);
div5:=m;
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.