Pagini recente » Cod sursa (job #3136775) | Cod sursa (job #995042) | Cod sursa (job #3293290) | Cod sursa (job #3039113)
#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;
if (p == 0) {
cout << "1" << endl;
return 0;
}
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;
}