#include #include #include "InfInt.h" using namespace std; template Number Factorial(const Number& n) { Number result = Number(1); for (Number i = Number(2); i <= n; ++i) { result *= i; } return result; } template Number N_Choose_M(const Number& n, const Number& m) { const Number result = Factorial(n) / Factorial(m) / Factorial(n - m); return result; } template Number B(const Number& n, const Number& m) { const Number maxK = n / m; Number sum = Number(0); for (Number k = Number(1); k <= maxK; ++k) { Number product = Number(1); for (Number j = Number(0); j < m; ++j) { const Number c = N_Choose_M(n - (k*j), k); product *= c; } sum += product; } const Number factorial = Factorial(m); const Number result = sum / factorial; return result; } template Number C(const Number& n) { const Number minM = Number(2); Number result = Number(0); for (Number m = minM; m <= n; ++m) { const Number b = B(n, m); result += b; } return result; } template void PrintValuesOfB(const Number& m, const Number& count) { const Number maxN = m + count; for (Number n = m; n <= maxN; ++n) { const Number b = B(n, m); int printLatex = 0; if (printLatex) { cout << "\\{{\\keyw " << n << "},{\\num " << b << "}\\}; " << endl; } else { cout << "b(" << n << ", " << m << ")=" << b << endl; } } } template void PrintValuesOfC(const Number& initialN, const Number& count) { const Number maxN = initialN + count; for (Number n = initialN; n <= maxN; ++n) { const Number b = C(n); int printLatex = 0; if (printLatex) { cout << "\\{{\\keyw " << n << "},{\\num " << b << "}\\}; " << endl; } else { cout << n << " " << b << endl; } } } int main() { try { typedef InfInt Number; const Number count = 200; const Number initialValue = 2; int printB = 0; if (printB) { PrintValuesOfB(initialValue, count); } else { PrintValuesOfC(initialValue, count); } } catch (exception& ex) { cout << "Error: " << ex.what() << endl; return 1; } catch (...) { cout << "Unknown error." << endl; return 2; } return 0; }