Cod sursa(job #234737)

Utilizator mist000000 mist Data 21 decembrie 2008 21:03:19
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
	long P, N;

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

	if (P == 0) {
		N = 1;
	}
	else {
		N = 0;
		while (P > 0) {
			long next = (N + 25) / 25;
			int bonus = 0;

			while (next % 5 == 0) {
				next /= 5;
				bonus++;
			}

			if (P < 6 + bonus && P >= 6) {
				N = -1;
				P = 0;
			} else if (P >= 6 + bonus) {
				P -= 6 + bonus;
				N += 25;
			} else {
				while (P > 0) {
					P--;
					N += 5;
				}
			}
		}
	}

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

	return 0;
}