Cod sursa(job #1937143)

Utilizator balazstasiTasi Balazs balazstasi Data 23 martie 2017 19:05:17
Problema Factorial Scor 60
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.81 kb
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.