Cod sursa(job #2614204)
| Utilizator | Data | 11 mai 2020 14:09:24 | |
|---|---|---|---|
| Problema | Factorial | Scor | 20 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.58 kb |
#include <iostream>
#include <fstream>
std::ifstream f("fact.in");
std::ofstream g("fact.out");
int findTrailingZeros(int n)
{
// Initialize result
int count = 0;
// Keep dividing n by powers of
// 5 and update count
for (int i = 5; n / i >= 1; i *= 5)
count += n / i;
return count;
}
int main()
{
int p;
f >> p;
if (p == 0) {
g << "1";
return 0;
}
int n = 5;
while (1)
{
int count = findTrailingZeros(n);
if (count == p) {
g << n;
return 0;
}
if (count > p) {
g << "-1";
return 0;
}
n+=5;
}
}