一般来说需要高精乘和高精除,但化简为质因子形式后只用高精乘。
一个阶乘n中因子p的个数:
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'using namespace std;typedef pair<int, int> PII;
typedef long long ll;
typedef long double ld;const int N = 5010;int num[N];
int primes[N], cnt;
bool st[N];vector<int> mul(vector<int> &A, int b)
{vector<int> C;int t = 0;for(int i = 0; i < A.size(); i ++){t += A[i] * b;C.push_back(t % 10);t /= 10;}while(t){C.push_back(t % 10);t /= 10;}return C;
}int get(int n, int p)//求阶乘n中因子p的个数
{int res = 0;while(n){res += n / p;n /= p;}return res;
}void get_primes()
{for(int i = 2; i <= 5000; i ++){if(!st[i])primes[cnt ++] = i;for(int j = 0; primes[j] * i <= 5000; j ++){st[primes[j] * i] = true;if(i % primes[j] == 0)break;}}
}int main()
{IOSint a, b;cin >> a >> b;get_primes();for(int i = 0; i < cnt; i ++){int p = primes[i];num[i] = get(a, p) - get(b, p) - get(a - b, p);}vector<int> A;A.push_back(1);for(int i = 0; i < cnt; i ++)for(int j = 0; j < num[i]; j ++)A = mul(A, primes[i]);for(int i = A.size() - 1; i >= 0; i --){cout << A[i];}return 0;
}