Pagini recente » Cod sursa (job #1170764) | Cod sursa (job #1300948) | Cod sursa (job #1306163) | Cod sursa (job #1279377) | Cod sursa (job #1937143)
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,100000000);
If p = 0 then Write(g,1)
else
Write(g,Vegso);
Close(f); Close(g);
END.