Pagini recente » Cod sursa (job #872382) | Cod sursa (job #207564) | Cod sursa (job #2755940) | Cod sursa (job #678259) | Cod sursa (job #1937110)
Program Factorial;
VAR
f,g : Text;
Vegso, p: LongInt;
Function Osztas (n : LongInt) : LongInt;
Begin
Osztas := 0;
While n > 0 do
begin
Osztas := Osztas + (n div 5);
n := n div 5;
end;
End;
Procedure BinarySearch (Left,Right : LongInt);
Var
Mid, Aux : LongInt;
Begin
While Left < Right do
begin
Mid := (Left + Right) div 2;
Aux := Osztas(Mid);
If Aux = p then
begin
Vegso := Mid;
Right := Mid - 1;
end
else
If Aux > P then
Right := Mid - 1
else
Left := Mid + 1;
end;
End;
BEGIN
Assign(f, 'fact.in'); Reset(f);
Assign(g, 'fact.out'); Rewrite(g);
ReadLn(f,p);
Vegso := -1;
BinarySearch(1,MaxLongInt);
If p = 0 then Write(g,0)
else
Write(g,Vegso);
Close(f); Close(g);
END.