Cod sursa(job #2063575)
Utilizator | Data | 11 noiembrie 2017 12:09:20 | |
---|---|---|---|
Problema | Factorial | Scor | 90 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.63 kb |
#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;
}
fout << ans;
fin.close();
fout.close();
return 0;
}