Pagini recente » Cod sursa (job #947521) | Cod sursa (job #3338454) | Cod sursa (job #3321927) | Cod sursa (job #3350590) | Cod sursa (job #3354185)
#include <iostream>
#include <fstream>
using namespace std;
typedef long long ll;
ll count_zeros(ll n) {
ll count = 0;
while (n > 0) {
n /= 5;
count += n;
}
return count;
}
int main() {
ifstream fin("fact.in");
ofstream fout("fact.out");
ll p;
if (!(fin >> p)) return 0;
if (p == 0) {
fout << 1 << endl;
return 0;
}
ll low = 1, high = 5000000000LL;
ll best_n = -1;
while (low <= high) {
ll mid = low + (high - low) / 2;
if (count_zeros(mid) >= p) {
best_n = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
if (best_n != -1 && count_zeros(best_n) == p) {
fout << best_n << endl;
} else {
fout << -1 << endl;
}
return 0;
}