Pagini recente » Cod sursa (job #2149809) | Cod sursa (job #2866544) | Cod sursa (job #134465) | Rating Razvan Tepeneu (razvantepeneu) | Cod sursa (job #2072024)
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int n, sol;
int nr(int m) {
int x = 5, q = 0;
while (m / x > 0) {
q += (m / x);
x *= 5;
}
return q;
}
void cb(int p, int u) {
if (p <= u) {
int m = (p + u) / 2;
if (nr(m) == n) {
sol = m;
cb(p, m - 1);
}
else
if (nr(m) > n)
cb(p, m - 1);
else
cb(m + 1, u);
}
}
int main()
{
fin >> n;
if (n == 0)
fout << 1;
else {
cb(1, n * 5);
if (sol != 0)
fout << sol;
else
fout << -1;
}
return 0;
}