Cod sursa(job #359157)

Utilizator eukristianCristian L. eukristian Data 25 octombrie 2009 21:54:01
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#include <iostream>
using namespace std;


int main()
{
	ifstream inFile;inFile.open("fact.in");
	ofstream outFile;outFile.open("fact.out");
	
	int n2 = 0 , n5 = 0 , p;
	inFile >> p;
	
	bool ok = true;int min = 0;
	int i;
	for (i = 1 ; ok ; ++i)
	{
		n2 = 0;n5 = 0;
		for (int j = 2 ; j <= i ; j += 2)
		{
			int x = j;
			while (x % 2 == 0)
			{
				n2++;
				x /= 2;
			}
		}
		
		for (int j = 5 ; j <= i ; j += 5)
		{
			int x = j;
			while (x % 5 == 0)
			{
				n5++;
				x /= 5;
			}
		}
		
		if (n2 > n5)
		{
			min = n5;
		}
		else 
		{
			min = n2;
		}
		
		if (min >= p)
		{
			ok = false;
		}
	}  
	--i;
	if (min == p)
	{
		outFile << i;
		cout << i;
	}
	
	else 
	{
		outFile << -1;
	}
	
	return 0;
}