Pagini recente » Cod sursa (job #1466867) | Cod sursa (job #1704050) | Cod sursa (job #10143) | Cod sursa (job #1155569) | Cod sursa (job #2615426)
#include <fstream>
using namespace std;
int main()
{
ifstream cin("fact.in");
ofstream cout("fact.out");
long long p;
cin>>p;
if(p==0)
{
cout<<"1"<<endl;
}
else
{
long long st=1,dr=p,mij,nr,ok=0;
while(dr>=st)
{
int mij=(st+dr)/2;
nr=1LL*mij*5;
long long put5=5,cnt=0;
while(put5<=nr)
{
cnt+=nr/put5;
put5*=5;
}
if(cnt==p)
{
cout<<nr<<'\n';
ok=1;
break;
}
if(cnt<p)
{
st=mij+1;
}
else
{
dr=mij-1;
}
}
if(ok==0)
{
cout<<"-1"<<endl;
}
}
return 0;
}