Cod sursa(job #2647148)

Utilizator IRadu1529Radu Ionescu IRadu1529 Data 3 septembrie 2020 13:53:09
Problema Factorial Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <deque>
#include <vector>
#include <fstream>

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

int multipluDe5(int nr)
{
	int x = 0;

	while (nr && nr % 5 == 0)
	{
		x++;

		nr /= 5;
	}

	return x;
}

int main()
{
	int n, limita, el, mult5, pow5, plus5;

	fin >> n;

	if (n == 0)
	{
		fout << 1;

		return 0;
	}

	if (n == 1)
	{
		fout << 5;

		return 0;
	}

	if (n == 2)
	{
		fout << 10;

		return 0;
	}

	el = 10;

	limita = 2;

	mult5 = 5;

	pow5 = 1;

	plus5 = 1;

	while (limita < n)
	{
		el += 5;

		if (el == mult5 * 5)
		{
			limita += ++pow5;

			plus5++;

			mult5 *= 5;
		}

		else
		{
			if (el % mult5 == 0)
				limita += plus5;
			
			else
				limita += multipluDe5(el);
		}
			
	}

	if (limita == n)
	{
		fout << el;

		return 0;
	}

	fout << -1;
}