#pragma once #include "real.hpp" #include namespace algoim { class Factorial { public: static std::vector cache; Factorial() { if (cache.empty()) cache.push_back(1); } static real calculate(int n) { if (n == 0) return 1; if (cache.size() <= n) { for (int i = cache.size(); i <= n; ++i) cache.push_back(cache.back() * i); } return cache[n]; } }; std::vector Factorial::cache; // 。 } // namespace algoim