Cod sursa(job #1600281)
| Utilizator | Data | 14 februarie 2016 20:35:42 | |
|---|---|---|---|
| Problema | Factorial | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.61 kb |
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
typedef unsigned long long ULL;
const ULL INF =-1;
int p;
int ndiv(ULL n)
{
ULL nrd = 0;
while (n > 0)
nrd += n/5, n /= 5;
return nrd;
}
ULL cb (ULL l, ULL r)
{
ULL mid, x;
while (l <= r)
{
mid = l+((r-l)/2);
x = ndiv(mid);
if (x < p)
l = mid+1;
else
r = mid-1;
}
if (ndiv(l) == p)
return l;
g << "-1";
return 0;
}
int main()
{
f >> p;
g << cb (1, INF);
return 0;
}
