nowcoder16543 求值2

链接

点击跳转

题解

用生成函数的思想来解决本题就挺好

考虑

( 1 + x ) n = C n 0 x 0 + C n 1 x 1 + C n 2 x 2 + (1+x)^n = C_n^0 x^0 + C_n^1 x^1 + C_n^2 x^2+\dots

考虑到我们想要的形式,不妨试一试两个上式相乘

( 1 + x ) n ( 1 + x ) n = ( C n 0 x 0 + C n 1 x 1 + C n 2 x 2 + ) ( C n 0 x 0 + C n 1 x 1 + C n 2 x 2 + ) (1+x)^n (1+x)^n = ( C_n^0 x^0 + C_n^1 x^1 + C_n^2 x^2+\dots )( C_n^0 x^0 + C_n^1 x^1 + C_n^2 x^2+\dots )

我们想要的是 C n i C n i = C n i C n n i \sum C_n^i C_n^i = \sum C_n^i C_n^{n-i} ,那这个东西不就是上面多项式之积的 n n 次项吗。

知道了我们要求的东西是 n n 次项的系数,接下来可以借鉴求留数的方法,对多项式求 n n 次导数,再带入 x = 0 x=0 ,即可得到想要的东西

代码

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define iinf 0x3f3f3f3f
#define linf (1ll<<60)
#define eps 1e-8
#define maxn 2000010
#define cl(x) memset(x,0,sizeof(x))
#define rep(_,__) for(_=1;_<=(__);_++)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define mod 998244353ll
#define de(x) cerr<<#x<<" = "<<x<<endl
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll read(ll x=0)
{
    ll c, f(1);
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-f;
    for(;isdigit(c);c=getchar())x=x*10+c-0x30;
    return f*x;
}
struct EasyMath
{
    ll prime[maxn];
    bool mark[maxn];
    ll fastpow(ll a, ll b, ll c)
    {
        ll t(a%c), ans(1ll);
        for(;b;b>>=1,t=t*t%c)if(b&1)ans=ans*t%c;
        return ans;
    }
    void get_prime(ll N)
    {
        ll i, j;
        for(i=2;i<=N;i++)mark[i]=false;
        *prime=0;
        for(i=2;i<=N;i++)
        {
            if(!mark[i])prime[++*prime]=i;
            for(j=1;j<=*prime and i*prime[j]<=N;j++)
            {
                mark[i*prime[j]]=true;
                if(i%prime[j]==0)break;
            }
        }
    }
}em;
ll fact[maxn], _fact[maxn], n, f[maxn], ans;
ll C(ll n, ll m)
{
    return fact[n]*_fact[m]%mod * _fact[n-m] %mod;
}
int main()
{
    ll i, j, ans=0, cnt;
    n=read();
    fact[0]=_fact[0]=1;
    rep(i,2e6)fact[i]=fact[i-1]*i%mod, _fact[i]=em.fastpow(fact[i],mod-2,mod);
    for(i=0;i<=n;i++)
    {
        ans += fact[2*i]*_fact[i]%mod*_fact[i]%mod;
        ans %= mod;
    }
    ans = (ans + mod - 1)%mod;
    printf("%lld",ans);
    return 0;
}
发布了863 篇原创文章 · 获赞 72 · 访问量 19万+

猜你喜欢

转载自blog.csdn.net/FSAHFGSADHSAKNDAS/article/details/104073679