Pagini recente » Cod sursa (job #2766887) | Cod sursa (job #2894222) | Cod sursa (job #276710) | Cod sursa (job #401315) | Cod sursa (job #900471)
Cod sursa(job #900471)
#include <fstream>
#define LL long long
using namespace std;
const char iname[] = "fact.in";
const char oname[] = "fact.out";
ifstream fin(iname);
ofstream fout(oname);
int P, a, b, mid;
LL c;
inline LL pow_5(int x)
{
LL s = 0;
while (x)
{
s += (x / 5);
x /= 5;
}
return s;
}
int main()
{
fin >> P;
a = 1; b = 500000000;
while (1)
{
mid = (a + b) / 2;
c = pow_5 (mid);
if (c == P && a == b){ fout << b << '\n'; return 0; }
if (a == b) { fout << -1 << '\n'; return 0; }
if (P > c)
a = mid + 1;
if (P <= c)
b = mid;
}
return 0;
}