Pagini recente » Rating Marinescu Gabriel (gabi.mar) | Istoria paginii runda/12345 | Rating Campean Alex (alexcam131) | Cod sursa (job #1565984) | Cod sursa (job #831374)
Cod sursa(job #831374)
#include<climits>
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int main()
{
int j=LONG_MAX,m,p,i=1,k,x,ok=0;
fin>>p;
if(p==0)fout<<"1";
while(i<=j && ok==0)
{
m=(i+j)/2;
x=5;
k=0;
while(x<=m)
{
k=k+m/x;
x=x*5;
}
if(k==p)ok=1;
else if(k>p)j=m-1;
else i=m+1;
}
if(ok==0)fout<<"-1";
else
{
while(m%5!=0)m--;
fout<<m;
}
fin.close();
fout.close();
return 0;
}