2020牛客暑期多校训练营(第一场)J-Easy Integration
2020牛客暑期多校训练营(第一场)\(J-Easy\) \(Integration\) 解题报告
题意:
计算:\(∫_0^1 (x - x^2)^ndx\)
思路:
\(n\) 次分部积分
分部积分公式(来源百度百科):
\[∫u(x)v^{'}(x)dx = u(x)v(x) - ∫u^{'}(x)v(x)dx
\]
那么:
\[∫_0^1 (x - x^2)^ndx = ∫_0^1x^n(1-x)^ndx
\]
\[= [\frac{x^{n+1}}{n+1}(1-x)^n]_0^1 - ∫_0^1\frac{x^{n+1}}{n+1}(-n(1-x)^{n-1})dx
\]
\[= \frac{n}{n+1}∫_0^1x^{n+1}(1-x)^{n-1}dx
\]
\[= \frac{n}{n+1}\times \frac{n-1}{n+2}\times ∫_0^1x^{n+2}(1-x)^{n-2}dx
\]
根据规律依次类推下去可得:
\[\texttt{原式 = } \frac{n}{n+1}\times\frac{n-1}{n+2}\times
\frac{n-2}{n+3}\times
...\times
\frac{1}{2n+1} = \frac{n!}{\frac{(2n+1)!}{n!}} = \frac{n!\times n!}{(2n+1)!}
\]
代码:
/*
@Author: nonameless
@Date: 2020-07-14 15:28:05
@Email: 2835391726@qq.com
@Blog: https://www.cnblogs.com/nonameless/
*/
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef pair<int, int> PII;
const double eps = 1e-8;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll LNF = 0x3f3f3f3f3f3f;
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a * b / gcd(a, b); }
const int MOD = 998244353;
const int N = 2e6 + 10;
ll f[N];
ll fastPow(ll a, ll b){
ll res = 1;
while(b){
if(b & 1) res = res * a % MOD;
b >>= 1;
a = a * a % MOD;
}
return res;
}
int main(){
f[0] = 1;
for(int i = 1; i < N; i ++)
f[i] = f[i - 1] * i % MOD;
int n;
while(cin >> n){
ll ans = f[n] * f[n] % MOD * fastPow(f[2*n+1], MOD - 2) % MOD;
cout << ans << endl;
}
return 0;
}