Pagini recente » Cod sursa (job #714649) | Cod sursa (job #2198652) | Cod sursa (job #995290) | Cod sursa (job #1850765) | Cod sursa (job #2063577)
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p, step = 1;
inline int test(int x) {
int ans = 0;
for (int i = 5; i <= x; i *= 5)
ans += x / i;
return ans;
}
int main()
{
fin >> p;
if (p == 0) {
fout << 1;
return 0;
}
int lim = 0x3f3f3f3f;
while ((step << 1) <= lim)
step <<= 1;
int ans = lim;
for (; step; step >>= 1) {
if (ans - step >= 0 && test(ans - step) >= p)
ans -= step;
}
if (test(ans) != p) {
fout << -1;
}
else
fout << ans;
fin.close();
fout.close();
return 0;
}