Pagini recente » Cod sursa (job #1529784) | Cod sursa (job #893522) | Cod sursa (job #3160354) | Cod sursa (job #2386665)
#include <fstream>
using namespace std;
ifstream fi("fact.in");
ofstream fo("fact.out");
const int nmax=2e9;
int p;
int numara(int x, int div)
{
int cnt=0, pw=div;
while(x/pw>0)
{
cnt+=x/pw;
pw*=div;
}
return cnt;
}
int bSearch(void)
{
int lo=1, hi=nmax, mid, res=-1;
while(lo<=hi)
{
mid=lo+(hi-lo)/2;
int nr0=min(numara(mid, 2), numara(mid, 5));
if(nr0==p)
{
res=mid;
hi=mid-1;
}
else if(nr0<p)
lo=mid+1;
else
hi=mid-1;
}
return res;
}
int main()
{
fi>>p;
fo<<bSearch();
fi.close();
fo.close();
return 0;
}