Pagini recente » Cod sursa (job #898028) | Cod sursa (job #2686386) | Cod sursa (job #943382) | Cod sursa (job #884663) | Cod sursa (job #673496)
Cod sursa(job #673496)
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define LL long long
LL P;
LL HM(LL X)
{
LL ans2 = 0, ans5 = 0;
LL p = 2;
while (X/p)
{
ans2 += X/p;
p *= 2;
}
p = 5;
while (X/p)
{
ans5 += X/p;
p *= 5;
}
return min(ans2, ans5);
}
int main()
{
freopen ("factorial.in", "r", stdin);
freopen ("factorial.out", "w", stdout);
scanf ("%lld", &P);
LL st = 1, dr = 1000000000000000000LL;
while (st < dr)
{
LL mij = (st + dr)/2;
if (HM(mij) >= P) dr = mij;
else st = mij + 1;
}
if (HM(st) == P) printf ("%lld", st);
else printf ("-1");
return 0;
}