Cod sursa(job #2772300)

Utilizator Gabryel9898Bizdoc Vasile Gabriel Gabryel9898 Data 31 august 2021 17:27:37
Problema Factorial Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.38 kb
#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 +=5;
        number_of_5 += get_number_of(5);
    }

    [[nodiscard]] int getInternalCounter() const {
        return counter;
    }
};


using namespace std::chrono;


int main() {
    auto start = high_resolution_clock::now();
    int target;

//    std::ifstream f1(stdin);
//    std::ofstream f2(stdout);

    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;
}