代码如下,不知到错哪里了,RE了
c++14
#include<bits/stdc++.h>
using namespace std;
#define LL long long
__int128 jc[2000005],ni[2000005],mod=998244353;
__int128 mp[1000005],n,m;
LL ksm(LL x,LL y){
LL ans=1,ret=x;
while(y){
if(y&1)ans=ans*ret%mod;
y=y>>1;ret=ret*ret%mod;
}
return ans;
}
void asd(){
jc[1]=jc[0]=ni[0]=ni[1]=1;
for(int i=2;i<=2e6;i++)jc[i]=jc[i-1]*i%mod;
ni[2000000]=ksm(jc[2000000],mod-2);
for(int i=2e6-1;i>1;i--)ni[i]=ni[i+1]*(i+1)%mod;
for(int i=1;i<=1e6+1;i++)mp[i]=i*(i+1)/2;
}
LL C(LL n,LL m){
return jc[n]*ni[m]%mod*ni[n-m]%mod;
}
int main (){
int t;
scanf("%d",&t);
asd();
while(t){
t--;
LL p;
scanf("%lld",&p);
m=0;
while(mp[m]<p)m++;
n=p-mp[m-1];
__int128 ans=0;
for(int i=0;i<=min(n-1,m-1);i++){
ans+=C(n+m-2-i,i)*((C(m+n-2-2*i,n-1-i)-C(m+n-2-2*i,n-2-i))%mod)%mod;
ans%=mod;
}
cout<<(long long )ans<<endl;
}
return 0;
}
自查极限数据500000500000会保龄
但就是不知道能错哪里