Cod sursa(job #1010460)

Utilizator TwoOfDiamondsDaniel Alexandru Radu TwoOfDiamonds Data 14 octombrie 2013 22:29:39
Problema Factorial Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <fstream>

using namespace std;

int nr0(int x)
{
	int ret = 0;

	for (int i = 5; i <= x ; i *= 5)
		ret += x/i;

	return ret;
}

int main()
{
	ifstream IN ("fact.in");
	ofstream OUT ("fact.out");

	int p; IN >> p;
	int noo5 = 0;
	int a = 1, b = p*5, c = (a+b) / 2;

	while (a <= b)
	{
		c = (a+b)/2;
		noo5 = nr0(c);
		if (noo5 >= p)
		{
			b = c - 1;
		}
			else
		{
			a = c + 1;
		}
	}
	
	if (noo5 == p)
	{
		OUT << c << "\n";
		return 0;
	}

	OUT << "-1\n";


	return 0;
}