Pagini recente » Cod sursa (job #2823584) | Cod sursa (job #1709441) | Cod sursa (job #1223165) | Cod sursa (job #1888576) | Cod sursa (job #1511420)
#include <fstream>
#include <climits>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
long long check(long long x)
{
long long nr0=0,h5=5;
while(h5<=x)
{
nr0=nr0+x/h5;
h5=h5*5;
}
return nr0;
}
int main()
{
long long p,l,r,mid,sol,g;
int ok;
fin>>p;
if (p==0){fout<<"1\n";}
else
{
l=1;
r=LONG_LONG_MAX;
ok=1;
while(l<=r)
{
mid=(l+r)/2;
g=check(mid);
if(g<p){l=mid+1;}
else
{
if(g==p){sol=mid;ok=0;}
r=mid-1;}
}
if(ok){fout<<"-1\n";}
else{fout<<sol<<"\n";}
}
}