Cod sursa(job #2072024)
| Utilizator | Data | 21 noiembrie 2017 12:29:18 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.62 kb |
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int n, sol;
int nr(int m) {
int x = 5, q = 0;
while (m / x > 0) {
q += (m / x);
x *= 5;
}
return q;
}
void cb(int p, int u) {
if (p <= u) {
int m = (p + u) / 2;
if (nr(m) == n) {
sol = m;
cb(p, m - 1);
}
else
if (nr(m) > n)
cb(p, m - 1);
else
cb(m + 1, u);
}
}
int main()
{
fin >> n;
if (n == 0)
fout << 1;
else {
cb(1, n * 5);
if (sol != 0)
fout << sol;
else
fout << -1;
}
return 0;
}
