Mai intai trebuie sa te autentifici.
Cod sursa(job #195616)
Utilizator | Data | 20 iunie 2008 11:03:08 | |
---|---|---|---|
Problema | Factorial | Scor | 10 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 0.65 kb |
var f,g:text;
a,b,p,c:longint;
function zero(c:longint):longint;
var x,p,d,nr:longint;
begin
dec(c,c mod 5);
x:=c div 5;
p:=25;
d:=p*5;
nr:=3;
while p<=c do begin
if d=p then begin
inc(x,nr);
d:=d*5;
inc(nr);
end
else inc(x,1);
inc(p,25);
end;
zero:=x;
end;
begin
assign(f,'fact.in');reset(f);
assign(g,'fact.out');rewrite(g);
read(f,p);
a:=1;
b:=100000000;
while (a<=b) do begin
c:=(a+b) div 2;
dec(c,c mod 5);
if zero(c)<p then a:=c+5;
if zero(c)>p then b:=c-5;
if zero(c)=p then begin
writeln(g,c);
break;
end;
end;
if a>b then writeln(g,'-1');
close(f);
close(g);
end.