Pagini recente » Cod sursa (job #733187) | Monitorul de evaluare | Cod sursa (job #1085570) | Cod sursa (job #1024103) | Cod sursa (job #2772422)
#include <fstream>
int zeros(int n) {
int res = 0;
while ((n = n / 5)) {
res += n;
}
return res;
}
void factorial() {
std::ifstream f1;
std::ofstream f2;
int target;
f1.open("fact.in");
f2.open("fact.out");
f1 >> target;
int start = 1;
int end = 400000015;
int number_of_zeroes;
int half;
do {
half = (start + end) / 2;
number_of_zeroes = zeros(half);
if (number_of_zeroes >= target) {
end = half;
} else if (number_of_zeroes < target) {
start = half + 1;
}
} while (start != end);
if (zeros(start) == target) {
f2 << start;
} else {
f2 << -1;
}
}
int main() {
factorial();
}