You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
const int N = 1010; // n+n=2n=> 500*2+10
int primes[N], cnt;
bool st[N];
int a[N], b[N];
void get_primes(int n) {
for (int i = 2; i <= n; i++) {
if (!st[i]) primes[cnt++] = i;
for (int j = 0; primes[j] * i <= n; j++) {
st[i * primes[j]] = true;
if (i % primes[j] == 0) break;
}
}
}
int get(int n, int p) { // n!中p的次数
int s = 0;
while (n) n /= p, s += n;
return s;
}
void mul(int a[], int b, int &len) {
int t = 0;
for (int i = 1; i <= len; i++) {
t += a[i] * b;
a[i] = t % 10;
t /= 10;
}
while (t) {
a[++len] = t % 10;
t /= 10;
}
//去前导0
while (len > 1 && !a[len]) len--;
}
int C(int a, int b, int c[]) {
int len = 1;
c[1] = 1;
for (int i = 0; i < cnt; i++) {
int p = primes[i];
int s = get(a, p) - get(b, p) - get(a - b, p);
while (s--) mul(c, p, len);
}
return len;
}
void sub(int a[], int b[], int &len) {
int t = 0;
for (int i = 1; i <= len; i++) {
t = a[i] - b[i] - t;
a[i] = (t + 10) % 10;
t < 0 ? t = 1 : t = 0;
}
while (len > 1 && !a[len]) len--;
}
int main() {
//加快读入
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
get_primes(2 * n);
int a1 = C(n + n, n, a);
int b1 = C(n + n, n - 1, b); // bl下面没有用到原因是两数相减我们知道a>b,按着a的长度来就行了
sub(a, b, a1);
for (int i = a1; i >= 1; i--) printf("%d", a[i]);
return 0;
}