牛客暑期多校训练营(第一场)J

 Easy Integration

 

hint:用分部积分法求定积分,如下图解

 

所以只需要求n ! ^ 2 / ( 2*n + 1 ) !就可以了 (!为阶乘).

由于n会比较大,用于除法会失精度,因此需要用到费马小定理:(当mod为质数时)a / b % mod = a * qpow(b , mod - 2) % mod;(qpow是快速幂)

AC代码: 

#include<bits/stdc++.h>
#define PB push_back
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define FI first
#define SE second
#define mem(a) memset(a,0,sizeof(a))
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;
const LL maxn = 1<<17;
const int mod = 998244353;
const int N = 2e6+5;
LL gcd(LL a,LL b) {
	return b?gcd(b,a%b):a;
}
LL lcm(LL a,LL b) {
	return a*b/gcd(a,b);
}
LL fac[N],inv[N];//inv表示n阶乘的逆元,fac[N]表示n阶乘
inline LL POW(LL x,LL y)
{
	LL ans=1;
	while(y){
		if(y&1)ans=ans*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return ans;
}
void init(){
	fac[0]=1;
	for(int i=1;i<N;i++){
		fac[i]=fac[i-1]*i%mod;
	}
	
	inv[N-1]=POW(fac[N-1],mod-2);//N-1的逆元
	for(int i=N-2;i>=0;i--)
	inv[i]=inv[i+1]*(i+1)%mod;
}
int main(){
	ios;int n;
	init();//预处理inv和fac数组
	while(cin>>n){
		cout<<fac[n]*fac[n]%mod*inv[2*n+1]%mod<<endl;
	}
	return 0;
}

以梦为马,不负韶华。冲冲冲~ 

猜你喜欢

转载自blog.csdn.net/weixin_43911947/article/details/107309924