Pagini recente » Cod sursa (job #1884245) | Cod sursa (job #648465) | Cod sursa (job #2074379)
#include <fstream>
using namespace std;
ifstream in ("fact.in");
ofstream out ("fact.out");
int L = 29;
int p;
int exp5 (int x)
{
int s = 0;
while (x >= 5)
s += (x /= 5);
return s;
}
int cautbin (int x)
{
int r = 0, pas = 1 << L;
while (pas != 0)
{
if (exp5 (r + pas) < p)
r += pas;
pas /= 2;
}
//if (exp5 (r + pas + 1) != p)
//r = -2;
return r + 1;
}
int main()
{
in >> p;
int r = cautbin (p);
if (p == 0)
out << 1;
else
{
if (exp5 (r) != p)
r = -1;
out << r;
}
return 0;
}