Pagini recente » Cod sursa (job #2355464) | Cod sursa (job #1953090) | Cod sursa (job #1909541) | Cod sursa (job #1737271) | Cod sursa (job #321776)
Cod sursa(job #321776)
#include<fstream.h>
#include<math.h>
long long p,mij,inc,sf,gasit,p2,t;
int main()
{
ifstream in("fact.in");
ofstream out("fact.out");
in>>p;
inc=5;
sf=5*p;
gasit=0;
while((gasit==0)&&(inc<=sf))
{ mij=(inc+sf)/2;
t=1;
p2=0;
while(t<=mij)
{t=t*5;
p2=p2+int(mij/t);
}
if(p2==p) gasit=1;
if(p2>p) sf=mij-1;
if(p2<p) inc=mij+1;
}
if(gasit==1) if(mij%5==0) out<<mij;
else {while(mij%5!=0)
mij=mij-1;
out<<mij;
}
else out<<"-1";
in.close();
out.close();
return 0;
}