Cod sursa(job #2352957)
| Utilizator | Data | 23 februarie 2019 19:25:20 | |
|---|---|---|---|
| Problema | Factorial | Scor | 30 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.5 kb |
#include <fstream>
using namespace std;
ifstream cin("fact.in");
ofstream cout("fact.out");
int nz(int n) {
int f = 5, r = 0;
while (n>=f) {
r+=n/f;
f *= 5;
}
return r;
}
int P, N;
int main() {
cin >> P;
if (P) {
N = 5 * P;
while (nz(N)>P)
N -= 5;
if (nz(N)<P) {
cout << -1;
} else {
cout << N;
}
} else {
cout << 1;
}
cin.close();
cout.close();
return 0;
}