Pagini recente » Cod sursa (job #2165101) | Cod sursa (job #2639082) | Cod sursa (job #460505) | Cod sursa (job #2373918) | Cod sursa (job #2739651)
#include <fstream>
#include <iostream>
int p, c=1;
long long int factorial = 1;
bool gasit = false;
int nrzero(int x) {
int c = 0; bool ok = true;
while (x) {
if (x % 10 == 0) {
c++;
}
else {
ok = false;
}
if (ok == false) {
break;
}
x /= 10;
}
return c;
}
int main() {
std::ifstream fin("fact.in");
std::ofstream fout("fact.out");
fin >> p;
if (p == 0) {
fout << 1;
}
else {
while (factorial < 999999999999999) {
factorial = 1;
for (int i = 1; i <= c; i++) {
factorial *= i;
}
if (nrzero(factorial) == p) {
fout << c;
gasit = true;
break;
}
c++;
}
if (gasit == false) fout << -1;
}
}