Cod sursa(job #1901923)
| Utilizator | Data | 4 martie 2017 12:00:07 | |
|---|---|---|---|
| Problema | Factorial | Scor | 55 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.88 kb |
#include <iostream>
#include <fstream>
using namespace std;
long long p, mijloc;
int nr0=0, i=0, x=1;
ifstream fin("fact.in");
ofstream fout("fact.out");
int factorial(long long x)
{
long long p5=5,f=0;
while(p5<=x)
{
f+=(x/p5);
p5*=5;
}
if(!x)
{
return 1;
}
else
{
return f;
}
}
int main()
{
fin>>p;
if(p==0)
{
fout<<1;
}
else
{
int i=0, s=1000000000;
while(s-i>1)
{
mijloc=(i+s)/2;
if(factorial(mijloc)<p)
{
i=mijloc+1;
}
else
{
s=mijloc;
}
}
if(factorial(i)!=p)
{
fout<<-1;
}
else
{
fout<<i;
}
}
return 0;
}
