Cod sursa(job #604790)

Utilizator andreii1Ilie Andrei andreii1 Data 25 iulie 2011 12:51:45
Problema Factorial Scor 95
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.67 kb
var st,mij,dr,n:longint;
    f,g:text;

function ecuatie(x:longint):longint;
var s,aux:longint;
begin
aux:=1;
s:=0;
while x>=aux do
        begin
        aux:=aux*5;
        s:=s+(x div aux);
        end;
ecuatie:=s;
end;


begin
assign(f,'fact.in');
reset(f);
assign(g,'fact.out');
rewrite(g);
read(f,n);
if n=0 then write(g,1) else
begin
st:=1;
dr:=5*n;
while st<>dr do
        begin
        mij:=(st+dr) div 2;
        if ecuatie(mij)>n then dr:=mij-1 else
        if ecuatie(mij)<n then st:=mij+1 else
        if ecuatie(mij)=n then dr:=mij;
        end;
if ecuatie(st)<>n then write(g,-1) else
write(g,st);
end;
close(f);
close(g);
end.