Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
173638 C班-陈乐 组合数的高精度算法 C++ 无测评数据 0 0 MS 0 KB 1344 2024-08-20 22:30:54

Tests(0/0):


#include <bits/stdc++.h> using namespace std; bool arr[1000001] = {false}; vector<int> ppn() { vector<int> pv; pv.push_back(2); int i,j; for (i = 3 ; i * i <= 1000000 ; i += 2) { if(!arr[i]) { pv.push_back(i); for (j = i * i ; j <= 1000000 ; j += i) arr[j] = true; } } while (i < 1000000) { if (!arr[i]) pv.push_back(i); i += 2; } return pv; } int cal(int x,int p) { int ans = 0; long long rec = p; while (x >= rec) { ans += x / rec; rec *= p; } return ans; } int pp(long long n,int k,int m) { long long ans = 1; while (k) { if (k & 1) ans = (ans * n) % m; n = (n * n) % m; k >>= 1; } return ans; } int c(int n,int m) { vector<int> pv = ppn(); long long ans = 1; int num; for (int i = 0 ; i < pv.size() && pv[i] <= n ; ++ i) { num = cal(n,pv[i]) - cal(m,pv[i]) - cal(n - m,pv[i]); ans = (ans * pp(pv[i],num,10007)) % 10007; } return ans; } int main() { int n,m; cin >> n >> m; cout << c(n + m - 2,n - 1); return 0; }