Pagini recente » Cod sursa (job #1320439) | Cod sursa (job #2883948) | Cod sursa (job #2082181) | Cod sursa (job #2050293) | Cod sursa (job #3252145)
// https://www.infoarena.ro/problema/fact
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int fact5 (const int x)
{
int n = 0;
for (int i = 5; i <= x; i *= 5)
n += x / i;
return n;
}
int searchInput(const int st, const int dr, const int target)
{
const int mid = (st + dr) / 2, val = fact5(mid);
if (st > dr)
return -1;
if (val == target)
return mid;
if (val > target)
return searchInput(st, mid - 1, target);
return searchInput(mid + 1, dr, target);
}
int main()
{
int p, sol;
fin >> p;
sol = searchInput(0, 600000, p);
if (sol != -1 && sol >= 5)
sol = sol - sol % 5;
else if (sol != -1)
sol = 1;
fout << sol;
return 0;
}