Pagini recente » Cod sursa (job #1496798) | Cod sursa (job #2801128) | Cod sursa (job #1472260) | Cod sursa (job #1477595) | Cod sursa (job #2482525)
#include <fstream>
using namespace std;
ifstream in ("fact.in");
ofstream out("fact.out");
int count_zero(int x) {
int p = 5, ct = 0;
while (p <= x) {
ct += x / p;
p *= 5;
}
return ct;
}
void fin(int x, int p) {
while (count_zero(x - 1) == p && x > 1) x --;
out << x;
}
void binary_search(int p, int st, int dr) {
while (st <= dr) {
int mij = (st + dr) / 2;
int x = count_zero(mij);
if (x == p) {
fin(mij, p);
return ;
} else if (x > p) {
dr = mij - 1;
} else {
st = mij + 1;
}
}
}
int main() {
int p;
in >> p;
binary_search(p, 1, 500000000);
return 0;
}