Cod sursa(job #979653)
| Utilizator | Data | 2 august 2013 11:40:47 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.55 kb |
#include <fstream>
#define nmax 500000000
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.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;
}
