Cod sursa(job #2842879)

Utilizator AlexandruPaulSirbu Alex AlexandruPaul Data 1 februarie 2022 17:44:39
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb

#include <iostream>

#include <fstream>

using namespace std;

ifstream fin("fact.in");

ofstream fout("fact.out");

int st, dr, x, p, n, m;

int main()

{

	fin >> p;

	if (p == 0)

	{

		fout << 1;

		return 0;

	}

	st = 1;

	dr = 800000000;

	while (st <= dr && n != p)

	{

		n = 0;

		m = (st + dr) / 2;

		x = m / 5;

		while (x)

		{

			n += x;

			x /= 5;

		}

		if (n > p)

			dr = m - 1;

		else

			st = m + 1;

	}

	if (st <= dr)

		fout << m - m % 5;

	else

		fout << -1;

	return 0;

}