Cod sursa(job #791693)

Utilizator alextudose95Tudose Stefan Alexandru alextudose95 Data 24 septembrie 2012 21:07:55
Problema Factorial Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.48 kb
program factorial;
var p,p1,i,x,n:longint;
      f,g:text;
begin
assign(f,'fact.in');reset(f);
assign(g,'fact.out');rewrite(g);
read(f,p);
if p=0 then n:=1
   else begin
    n:=5*p;
for i:=1 to 5 do begin
  x:=5;
  p1:=0;
  repeat
  p1:=p1+trunc(n/x);
  x:=x*5
  until x>n;
     if p1>p then n:=n-1
        else if p1<p then n:=n-1
         else if p1<p then
           n:=n+1;
     if n mod 5<>0 then n:=n-1;
end;
 end;
if p1<>p then n:=-1;
write(g,n);
close(g);
end.