Cod sursa(job #2237520)
| Utilizator | Data | 2 septembrie 2018 02:11:15 | |
|---|---|---|---|
| Problema | Factorial | Scor | 20 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.93 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main () {
int p, fact = 1, putere = 1, n = 5;
bool gasit = false;
ifstream in ("fact.in");
in >> p;
in.close();
for (int i = 1; i <= p; i++) {
putere *= 5;
}
do {
if (p == 0) {
ofstream out ("fact.out");
out << 1;
out.close();
gasit = true;
} else if (fact % putere == 0) {
if (fact % (putere * 5) == 0) {
ofstream out ("fact.out");
out << -1;
out.close();
} else {
ofstream out ("fact.out");
out << n - 5;
out.close();
}
gasit = true;
}
fact *= n;
n += 5;
} while (!gasit);
return 0;
}