Cod sursa(job #579781)

Utilizator BlackElfSpulber Iosif BlackElf Data 12 aprilie 2011 14:17:27
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#include <iostream>
#include <fstream>

using namespace std;

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

	long long p;
	long long i = 5;
	long long c = 0;
	long long a;

	in >> p;

	if (p == 0)
	{
		out << 1 << endl;
		return 0;
	}

	if (p < 0)
	{
		out << -1 << endl;
		return 0;
	}
	
	while (c < p)
	{
		a = i;
		while (a % 5 == 0)
		{
			c++;
			a /= 5;
		}

		i+=5;
	}

	out << i - 5;

	return 0;
}