Pagini recente » Cod sursa (job #1956113) | Cod sursa (job #2771186) | Cod sursa (job #2454023) | Cod sursa (job #1458323) | Cod sursa (job #2463024)
#include <bits/stdc++.h>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int n;
int f(int x) {
int ans = 0;
for (int i = 5; x / i >= 1; i *= 5) {
ans += x / i;
}
return ans;
}
int search_for(int cnt) {
int l = 1, r = 2e9;
while(l <= r) {
int mid = (l + r) / 2;
if (f(mid) < cnt) {
l = mid + 1;
}
else {
r = mid - 1;
}
}
if (f(l) == cnt) return l;
return -1;
}
int main() {
in >> n;
int ans = search_for(n);
return out << ans, 0;
}