Cod sursa(job #833279)
| Utilizator | Data | 12 decembrie 2012 10:46:35 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.68 kb |
#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) break;
if (m<p) min=x+1;
else max=x;
}
if (f(x)==p)
{
while (f(x-1)==p)
x--;
fout<<x;
}
else fout<<"-1";
return 0;
}
