Pagini recente » Cod sursa (job #2945274) | Profil coronavirus | Cod sursa (job #3269049) | Cod sursa (job #3173885) | Cod sursa (job #3294223)
#include <fstream>
using namespace std;
ifstream fin ("fact.in");
ofstream fout ("fact.out");
int caut_bin (int p, bool & gasit) {
int val = -1, st = 1, dr = 1e9;
while (st <= dr) {
int mij = st + (dr - st) / 2;
int put = 5, cnt = 0;
while (put <= mij) {
cnt += mij / put;
put *= 5;
}
if (cnt == p) {
gasit = true;
val = mij;
dr = mij - 1;
}
else {
if (cnt > p)
dr = mij - 1;
else
st = mij + 1;
}
}
return val;
}
int main () {
int p;
fin >> p;
bool gasit = false;
int n = caut_bin (p, gasit);
if (!gasit)
fout << -1;
else
fout << n;
return 0;
}