Cod sursa(job #234739)
#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 >= 5) {
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");
out << N << endl;
out.close();
return 0;
}