Pagini recente » Cod sursa (job #1222135) | Cod sursa (job #1105454) | Cod sursa (job #2107494) | Cod sursa (job #857934) | Cod sursa (job #833282)
Cod sursa(job #833282)
#include<fstream>
using namespace std;
long long f(long long x)
{
int p=5,nr=0;
while (p<=x)
{
nr=nr+x/p;
p=p*5;
}
return nr;
}
int main()
{
ifstream fin("fact.in");
ofstream fout("fact.out");
long long p, max=1000000000, min=1, x, m;
fin>>p;
if (p==0)
{
fout<<"1\n";
return 0;
}
else
while (min<max)
{
x=(min+max)/2;
m=f(x);
if (m<p) min=x+1;
else max=x;
}
if (f(x)==p)
{
fout<<x;
}
else fout<<"-1";
return 0;
}