Pagini recente » Cod sursa (job #141042) | Cod sursa (job #2583706) | Cod sursa (job #714747) | Cod sursa (job #1734496) | Cod sursa (job #1366495)
#include <fstream>
using namespace std;
ifstream fin ("fact.in");
ofstream fout ("fact.out");
int main ()
{
int p,c,gasit;
long long s,d,m,x;
s=1;
d=1000000000;
fin>>p ;
gasit=0;
while(s<=d && gasit==0)
{
m=(s+d)/2;
x=m;
c=0;
while(x!=0)
{
c=c+x/5 ;
x=x/5;
}
if(c==p)
{
if(p==0) fout<<"1";
else fout<<m-m%5;
gasit=1;
}
else if (c>p) d=m-1;
else s=m+1;
}
if(gasit==0) fout<<"-1";
fin.close();
fout.close();
return 0;
}