Cod sursa(job #600907)

Utilizator luckyme91wiz kid luckyme91 Data 4 iulie 2011 02:20:50
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <iostream>
#include <fstream>

using namespace std;

int main () {

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

int n, i, count ,temp, fives;

in >> n;
count = 0;
fives = 0;
for (i = 1;count < n; i++)
{
	if (i % 5 != 0)
		count++;
	else
	{
		temp = i;
		while (temp % 5 == 0)
		{
			if (temp % 5 == 0 && temp % 10 != 0)
			{
				fives ++;
				count += fives;
				break;
			}
			else
			{
				temp /= 5;
				count ++;
			}
		}
		count ++;
	}
	
	if (count == n)
	{
		out << i * 5;
		break;
	}

}
if (n == 0)
	out << 1;
else
	if (count > n)
		out << -1;
return 0;
}