Cod sursa(job #2644974)
| Utilizator | Data | 26 august 2020 16:58:16 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.62 kb |
#include <bits/stdc++.h>
using namespace std;
int32_t main()
{
ios::sync_with_stdio(false), cin.tie(nullptr);
freopen("fact.in", "r", stdin);
freopen("fact.out", "w", stdout);
int p; cin >> p;
int64_t l = 1, r = INT_MAX, it = 300, ans = INT_MAX;
bool found = 0;
while (it--) {
int64_t a = (l + r) / 2;
int64_t cnt = 0, i = 5;
while (a / i) cnt += a / i, i *= 5;
if (cnt >= p) {
if (cnt == p) ans = min(ans, a), found = 1;
r = a;
} else {
l = a;
}
}
cout << (found ? ans : -1);
return 0;
}