Pagini recente » Grigore Moisil 2010 | Babacu | Profil tabara | Clasament dupa rating | Cod sursa (job #2897029)
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
unsigned long long p, sol = 1, st, dr, mij, nr;
unsigned long long fact5(unsigned long long x)
{
unsigned long long p = 5, sol = 0, lastp = 1;
while (p <= x && p > lastp)
{
sol += x / p;
lastp = p;
p *= 5;
}
return sol;
}
int main()
{
f >> p;
st = 1;
dr = p * 10;
while (st <= dr)
{
mij = (st + dr) / 2;
nr = fact5(mij);
if (nr >= p)
{
sol = mij;
dr = mij - 1;
}
else
st = mij + 1;
}
g << sol;
return 0;
}