提交时间:2024-08-20 16:00:42

运行 ID: 169258

#include <iostream> #include <boost/multiprecision/cpp_int.hpp> using namespace boost::multiprecision; using namespace std; int main() { int n; cin >> n; cpp_int factorial = 1; for (int i = 2; i <= n; i++) { factorial *= i; } cout << factorial << endl; return 0; } #include <iostream> #include <bits/stdc++.h> using namespace std; const int MAXN = 1005; // 高精度加法 void add(vector<int>& a, vector<int>& b) { int carry = 0; for (int i = 0; i < a.size() || i < b.size(); i++) { if (i < a.size()) carry += a[i]; if (i < b.size()) carry += b[i]; if (i < a.size()) a[i] = carry % 10; else a.push_back(carry % 10); carry /= 10; } if (carry) a.push_back(carry); } // 高精度乘法 void multiply(vector<int>& a, int b) { int carry = 0; for (int i = 0; i < a.size(); i++) { carry += a[i] * b; a[i] = carry % 10; carry /= 10; } while (carry) { a.push_back(carry % 10); carry /= 10; } } // 计算组合数C(n, m) vector<int> combination(int n, int m) { vector<int> result(1, 1); for (int i = 1; i <= m; i++) { multiply(result, n - i + 1); multiply(result, 1); } return result; } int main() { int M, N; cin >> M >> N; vector<int> result = combination(M + N - 2, min(M - 1, N - 1)); int pathCount = 0; for (int i = 0; i < result.size(); i++) pathCount += result[i]; cout << pathCount << endl; return 0; }