Pagini recente » Rezultatele filtrării | Cod sursa (job #2429507)
#include <fstream>
using namespace std;
ifstream f ("fact.in");
ofstream g ("fact.out");
int cntZeros (int n)
{
int pow = 5;
int cnt = 0;
while (pow <= n)
{
cnt += (n/pow);
pow *= 5;
}
return cnt;
}
int main ()
{
int n;
f>>n;
int st, dr, mij;
st = 1;
dr = cntZeros(100000000);
bool gasit = false;
while (st < dr)
{
mij = ((st + dr) / 2);
int cnt = cntZeros (mij);
if (cnt == n)
{
gasit = true;
break;
}
else if (cnt < n)
st = mij+1;
else
dr = mij-1;
}
if (gasit)
g<<(mij/5)*5;
else
g<<-1;
return 0;
}