Pagini recente » Cod sursa (job #3295250) | Cod sursa (job #903704) | Cod sursa (job #1160404) | Cod sursa (job #792766) | Cod sursa (job #979651)
Cod sursa(job #979651)
#include <fstream>
#define nmax 500000000
using namespace std;
ifstream fin("factorial.in");
ofstream fout("factorial.out");
int p,hi,lo,x,mid,s;
int main()
{
fin>>p;
lo=0;
hi=nmax;
while (hi-lo>1)
{
mid = (hi+lo)/2;
x=mid; s=0;
while (x!=0)
{
s += x/5;
x/=5;
}
if (p <= s) hi = mid;
else lo = mid;
}
x=hi; s=0;
while (x!=0)
{
s += x/5;
x/=5;
}
if (p==s) fout<<hi;
else fout<<-1;
}