Pagini recente » Cod sursa (job #1813703) | Cod sursa (job #2558767) | Cod sursa (job #3178908) | Cod sursa (job #777226) | Cod sursa (job #600950)
Cod sursa(job #600950)
#include <iostream>
#include <fstream>
using namespace std;
int zeros (int x)
{
int count = x, den = 5;
while (x >= den)
{
count += x/den;
den *= 5;
}
return count;
}
int bsearch (int begin, int end, int x)
{
if (begin <= end)
{
int half = (begin + end)/2;
int zero = zeros(half);
if (x > zero)
return bsearch(half + 1, end, x);
if (x < zero)
return bsearch(begin, half - 1, x);
if (x == zero)
return half;
}
else
return -1;
}
int main () {
ifstream in ("fact.in");
ofstream out ("fact.out");
int n, i, count, den;
in >> n;
if (n == 0)
{
out << 1;
return 0;
}
int sol = bsearch (1, n, n);
if (sol > 0)
out << sol * 5;
else
out << -1;
return 0;
}