Pagini recente » Cod sursa (job #3177245) | Cod sursa (job #2241987) | Cod sursa (job #76904) | Borderou de evaluare (job #2013043) | Cod sursa (job #903716)
Cod sursa(job #903716)
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int getzero(const int& x)
{
int y = 5, cnt = 0;
while (y <= x)
{
cnt = cnt + x / y;
y *= 5;
}
return cnt;
}
int binary(int left, int right, const int& p)
{
if (left > right) return -1;
else
{
int mij = (right-left) / 2 + left;
int n = getzero(mij);
if (n == p) return mij;
else if (n > p) return binary(left, mij-1, p);
else return binary(mij+1, right, p);
}
}
int main()
{
int P; in >> P;
int n;
if (P == 0) { out << 1; return 0; }
n = binary(1, int(2e9), P);
if (n > 0) while (n % 5 != 0) --n;
out << n;
return 0;
}