Pagini recente » Istoria paginii runda/pregatire-lot-aib | Cod sursa (job #2890468) | Istoria paginii runda/r1/clasament | Cod sursa (job #961145) | Cod sursa (job #13396)
Cod sursa(job #13396)
var f,g:text;
a,b,x,m,fact,suma,p,r:longint;
ok:boolean;
function zerouri(w:longint):longint;
var fact,max:longint;
begin
fact:=5;max:=0;
while w div fact<>0 do
begin
max:=max+w div fact;
fact:=fact*5;
end;
zerouri:=max;
end;
begin
assign(f,'fact.in');
reset(f);
read(f,p);
close(f);
b:=1500000000;
a:=0;
ok:=true;
suma:=0;
assign(g,'fact.out');
rewrite(g);
while (a<>b)and(ok) do
begin
x:=(a+b) div 2;
m:=x;
suma:=zerouri(x);
if suma=p then
begin
while (suma=p)and(m>0) do
begin
m:=m-1;
r:=m;
ok:=false;
suma:=zerouri(r);
end;
write(g,m+1);
end
else
if suma<p then
begin
a:=(a+b) div 2;
end
else
if suma >p then
b:=(a+b) div 2;
end;
if a=b then
write(g,-1);
close(g);
end.