Pagini recente » Cod sursa (job #915757) | Cod sursa (job #920206) | Cod sursa (job #1385811) | Cod sursa (job #2772416) | Cod sursa (job #2772296)
#include <iostream>
#include <chrono>
class Factorial {
private:
int counter = 0;
int number_of_2 = 0;
int number_of_5 = 0;
[[nodiscard]] int get_number_of(int number) const {
int counter_copy = counter;
int result = 0;
while (counter_copy && counter_copy % number == 0) {
++result;
counter_copy /= 5;
}
return result;
}
public:
[[nodiscard]] int findTrailingZeros() const {
return std::min(number_of_2, number_of_5);
}
void next() {
++counter;
number_of_5 += get_number_of(5);
number_of_2 += get_number_of(2);
}
[[nodiscard]] int getInternalCounter() const {
return counter;
}
};
using namespace std::chrono;
int main() {
auto start = high_resolution_clock::now();
// auto target = std::pow(10, 8);
auto target = 2;
auto f = new Factorial();
while (f->findTrailingZeros() != target) {
f->next();
}
std::cout << f->getInternalCounter();
// for (int i = 0; i < std::pow(10, 8); ++i) {
// }
auto stop = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stop - start);
std::cout << std::endl << "[time]:" << duration.count() << std::endl;
return 0;
}