Cod sursa(job #1010462)

Utilizator TwoOfDiamondsDaniel Alexandru Radu TwoOfDiamonds Data 14 octombrie 2013 22:31:56
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 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 a = 1, b = p*5, c = (a+b) / 2;

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

	OUT << "-1\n";


	return 0;
}