Pagini recente » Cod sursa (job #1437343) | Cod sursa (job #2262151) | Cod sursa (job #2801983) | Cod sursa (job #2139263) | Cod sursa (job #2486373)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("fact.in");
ofstream g ("fact.out");
int nrzero(int x) {
int p = 5, ct = 0;
while (p <= x) {
ct += x / p;
p *= 5;
}
return ct;
}
void fin(int x, int p) {
while (nrzero(x - 1) == p && x > 1)
x --;
g << x;
}
void cautare(int p, int st, int dr) {
while (st <= dr) {
int mij = (st + dr) / 2;
int x = nrzero(mij);
if (x == p) {
fin(mij, p);
return ;
} else if (x > p) {
dr = mij - 1;
} else {
st = mij + 1;
}
}
g << "-1";
}
int main() {
int p;
f >> p;
if (p == 0)
g << "1";
else
cautare(p, 1, 5 * p);
return 0;
}