Cod sursa(job #3039111)
Utilizator | Stana Andrei pregoli | Data | 28 martie 2023 10:37:40 |
---|---|---|---|
Problema | Factorial | Scor | 95 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.65 kb |
#include <iostream>
#include <stdio.h>
using namespace std;
int zerosOfFact(int x) {
int cnt = 0;
while (x >= 5) {
x /= 5;
cnt += x;
}
return cnt;
}
int main() {
freopen("fact.in", "r", stdin);
freopen("fact.out", "w", stdout);
int p;
cin >> p;
int low = 0, high = 1e9;
while (low <= high) {
int mid = (low + high) / 2;
if (zerosOfFact(mid) == p) {
cout << 5 * (mid / 5) << endl;
return 0;
}
if (zerosOfFact(mid) < p) {
low = mid + 1;
} else {
high = mid - 1;
}
}
cout << -1 << endl;//*/
return 0;
}