最初に
C++で書かれた、カタラン数コードです。表記
カタラン数情報
カタラン数 WikipediaC++コード
/** * カタラン数を返す * @param [in] n 要素数 * @return カタラン数を返す */ template<typename IntType> IntType Catalan(IntType x) { if (x == 0) return 1; IntType n = x << 1; IntType result = n; for (IntType i = 2; i <= x; ++i) { result *= (n - i + 1); result /= i; } return result/(x+1); }