Cod sursa(job #234733)

Utilizator mist000000 mist Data 21 decembrie 2008 20:49:29
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.44 kb
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
	long long P, N;

	ifstream in("fact.in");
	in >> P;
	in.close();

	if (P == 0) {
		N = 1;
	}
	else if (P % 6 == 5) {
		N = -1;
	}
	else {
		long inc = 5 * 5;	// brings factor 5 a total of 6 times
		N = 0;
		while (P >= 6) {
			N += inc;
			P -= 6;
		}
		while (P > 0) {
			N += 5;
			P--;
		}
	}

	ofstream out("fact.out");
	out << N << endl;
	out.close();

	return 0;
}