Pagini recente » Cod sursa (job #1616225) | Cod sursa (job #2681509) | Cod sursa (job #184459) | Cod sursa (job #2232276) | Cod sursa (job #2131659)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
long long p;
int zero(int x)
{
long long s = 0;
while(x >= 5)
{
s = s + x / 5;
x = x / 5;
}
return s;
}
int cautbin(int x)
{
long long st = 0, mij, dr=1000000000;
while(st < dr)
{
mij = (st + dr)/2;
if(zero(mij) > p)dr = mij;
else st = mij +1;
}
st -= 5;
return st;
}
int main()
{
fin >> p;
if(p == 0)fout << 1;
else if(zero(cautbin(p)) != p)
fout << "-1";
else fout << cautbin(p);
}