1. 程式人生 > 實用技巧 >2020牛客暑期多校訓練營(第一場)J-Easy Integration

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:  [email protected]
@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;
}