You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
439 B
24 lines
439 B
#pragma once
|
|
#include "real.hpp"
|
|
#include <vector>
|
|
|
|
namespace algoim
|
|
{
|
|
class Factorial
|
|
{
|
|
public:
|
|
static std::vector<real> cache;
|
|
|
|
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[i - 1] * i);
|
|
}
|
|
return cache[n];
|
|
}
|
|
};
|
|
|
|
std::vector<real> Factorial::cache = {1}; // 。
|
|
|
|
} // namespace algoim
|