Pagini recente » Cod sursa (job #2164202) | Cod sursa (job #1658444) | Cod sursa (job #1889559) | Cod sursa (job #1524465) | Cod sursa (job #2074354)
#include <fstream>
using namespace std;
ifstream in ("fact.in");
ofstream out ("fact.out");
int L = 27;
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, i = 0;
while (pas != 0)
{
if (exp5 (r + pas) <= p)
r += pas;
pas /= 2;
}
if (exp5 (r + pas) != p)
r = -1;
else
while (exp5 (r + pas) == p)
{
r --;
i ++;
}
return r + 1;
}
int main()
{
in >> p;
if (p == 0)
out << 1;
out << cautbin (p);
return 0;
}