Pagini recente » Cod sursa (job #106477) | Cod sursa (job #2503197) | Cod sursa (job #1647988) | Cod sursa (job #2630299) | Cod sursa (job #1511407)
#include <fstream>
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;
int ok;
fin>>p;
l=1;
r=9223372036854775807;
ok=1;
while(l<=r)
{
mid=(l+r)/2;
if(check(mid)<p){l=mid+1;}
else{r=mid-1;sol=mid;ok=0;}
}
if(ok){fout<<"-1\n";}
else{fout<<sol<<"\n";}
}