Cod sursa(job #2739650)
| Utilizator | Data | 9 aprilie 2021 03:16:22 | |
|---|---|---|---|
| Problema | Factorial | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.56 kb |
#include <fstream>
int p, n=1, c=1;
long long int factorial = 1;
bool gasit = false;
int nrzero(int x) {
int c = 0;
while (x) {
if (x % 10 == 0) c++;
x %= 10;
}
return c;
}
int main() {
std::ifstream fin("fact.in");
std::ofstream fout("fact.out");
fin >> p;
if(p < 0) return 0;
while (factorial < 999999999999999 ) {
factorial = 1;
for (int i = 1; i <= c; i++) {
factorial *= i;
}
if (nrzero(factorial) == p) {
fout << factorial;
gasit = true;
break;
}
c++;
}
if (gasit == false) fout << -1;
}