Pagini recente » Cod sursa (job #520825) | Cod sursa (job #2952619) | Cod sursa (job #2780890) | Cod sursa (job #1345971) | Cod sursa (job #52046)
Cod sursa(job #52046)
var a,z,w,p:int64;
li,lf:int64;
//a,z:int64;
procedure cautare_bin(li,lf:longint);
var i:int64;
begin
a:=(li+lf) div 2;
i:=1;
w:=0;
while a div i>0 do
begin
w:=w+a div i;
i:=i*5;
end;
end;
procedure cautare;
var gasit:boolean;
begin
li:=1;
lf:=100000000;
gasit:=false;
if p=0 then
a:=1
else begin
while li<=lf do
begin
cautare_bin(li,lf);
if w=p then
begin
if not gasit then
z:=a
else begin
if a<z then z:=a;
end;
gasit:=true;
end;
if w<p then
begin
li:=a+1;
end
else begin
lf:=a-1;
end;
end;
if not gasit then
a:=-1;
end;
end;
procedure scriere;
begin
assign(output,'fact.out');
rewrite(output);
write(a);
close(output);
end;
procedure citire;
begin
assign(input,'fact.in');
reset(input);
read(p);
close(input);
end;
begin
citire;
cautare;
scriere;
end.