The first J.Easy Integration definite integral formula derives the factorial inverse element

topic

https://ac.nowcoder.com/acm/contest/5666/J
Find a definite integral and express the result with an inverse element

Derivation of definite integral formula:

It seems that Wallis' integrals
actually find the first few, and then oeis can find the rule,
but it can also be done for definite integrals
Insert picture description here
Insert picture description here

Ideas:

The formula is obtained, the next step is to find the inverse element. I feel that the ordinary inverse element will explode. Here, the factorial inverse element is used.

Code:

#include<bits/stdc++.h>
#define mem(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
const ll maxn=2e6+10;
const ll MOD=998244353;
ll T,n,t;
ll fac[maxn+10],inv[maxn+10];
ll QPow(ll x, ll n)
{
    
    
    ll ret = 1;
    ll tmp = x % MOD;

    while (n)
    {
    
    
        if (n & 1)
        {
    
    
            ret = (ret * tmp) % MOD;
        }
        tmp = tmp * tmp % MOD;
        n >>= 1;
    }

    return ret;
}
void init()
{
    
    
    fac[0] = 1;
    for (int i = 1; i < maxn; i++)
    {
    
    
        fac[i] = fac[i - 1] * i % MOD;
    }
    inv[maxn - 1] = QPow(fac[maxn - 1], MOD - 2);
    for (int i = maxn - 2; i >= 0; i--)
    {
    
    
        inv[i] = inv[i + 1] * (i + 1) % MOD;
    }
}
bool flag;
int main()
{
    
    
    init();
    while(scanf("%lld",&n)!=EOF)
    {
    
    
        t=(((fac[n]*fac[n])%MOD)*inv[2*n+1])%MOD;
        cout<<t<<endl;
    }
    return 0;
}


Guess you like

Origin blog.csdn.net/STL_CC/article/details/107340851