Cod sursa(job #1375556)

Utilizator robertforyouNo Name robertforyou Data 5 martie 2015 13:37:23
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
int main()
{ifstream in;
	ofstream out;
	long long int P, i = 0, o = 0, M = 1, k;
	in.open("fact.in");
	in >> P;
	in.close();
	bool cifre = false;
	if (P == 0)
	{cifre = true;
		i = 1;}
	while (cifre == false)
	{o = 0;
		i = i + 1;
		if (i % 5 == 0 || i == 4)
		{M = M*i;
			while (M % 3 == 0) M = M / 3;}
		k = M;
		if (i % 5 == 0)
		{while (k % 10 == 0)
			{o = o + 1;
					k = k / 10;}}
		if (o == P)
		{cifre = true;}
		else if (o > P)
		{cifre = true;
			i = -1;}}
	out.open("fact.out");
	out << i;
	out.close();
	return 0;
}