Pagini recente » Borderou de evaluare (job #243906) | Borderou de evaluare (job #2012028) | Cod sursa (job #1804903) | Cod sursa (job #1800376) | Cod sursa (job #2772411)
#include <iostream>
#include <chrono>
#include <fstream>
using namespace std::chrono;
std::ifstream f1("fact.in");
std::ofstream f2("fact.out");
long long zeros(long long n) {
long long res = 0;
while (n = n / 5) {
res += n;
}
return res;
}
void factorial() {
int target;
// std::ifstream f1("../in.txt");
// std::ofstream f2("../out.txt");
f1 >> target;
long long end = 1e10;
long long start = 1;
long long zr;
long long half;
do {
half = (start + end) / 2;
zr = zeros(half);
if (start == end && zr != target) {
f2 << -1;
return;
}
if (zr > target) {
end = half;
} else {
start = half + 1;
}
} while (zr != target);
int endWith = half % 10;
if (endWith > 5) {
half -= endWith;
half += 5;
} else {
half -= endWith;
}
f2 << half;
}
int main() {
auto start = high_resolution_clock::now();
factorial();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stop - start);
std::cout << std::endl << "[time]:" << duration.count() << std::endl;
return 0;
}