Cod sursa(job #1211149)

Utilizator ValyGabrielMitrea Valentin Gabriel ValyGabriel Data 22 iulie 2014 00:31:08
Problema Factorial Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>

using namespace std;


int factorial(int p)
{
	if (p == 0)
		return 1;

	int nr = 0, n = 5, aux;

	while (1)
	{
		aux = n;

		while (aux % 10 == 0)
		{
			nr ++;
			aux /= 10;
		}

		while (aux % 5 == 0)
		{
			nr ++;
			aux /= 5;
		}

		if (nr > p)
			return -1;
		else if (nr == p)
			return n;
		
		n += 5;
	}
}


int main(int argc, char** argv)
{
	int p;
    
    ifstream in("fact.in");
    ofstream out("fact.out");
    
    in >> p;
    out << factorial(p);

    in.close();
	out.close();
    
	return 0;
}