Pagini recente » Cod sursa (job #2578527) | Cod sursa (job #2481227) | Cod sursa (job #3218505) | Cod sursa (job #793163) | Cod sursa (job #2772299)
#include <iostream>
#include <chrono>
#include <fstream>
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 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);
int target;
std::ifstream f1("fact.in");
std::ofstream f2("fact.out");
f1 >> target;
auto f = new Factorial();
while (f->findTrailingZeros() != target) {
f->next();
}
f2 << 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;
}