2020牛客多校第一场 J

第一种方法,直接用分部积分的算法,递推下去,最后可以得到结果
书写潦草,大致写法
在这里插入图片描述
方法二: 直接调用贝塔函数,对比系数法,就可以的到公式
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
对于 p/q % mod 这种,当mod为奇数的时候,就可以用快速幂方法求逆元

代码:

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
 
const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const int mod = 998244353;
const int N = 2000010;

int fact[N],infact[N];

int qmi(int a,int b){
	int res = 1;
	while(b){
		if(b&1) res = res*a%mod;
		a = a*a%mod;
		b >>= 1;
	}
	return res;
}

void init(){//这里不用infact存,直接求逆元更快qmi(fact[2*n+1],mod-2)
	fact[0] = infact[0] = 1;
	for(int i=1;i<N;i++){
		fact[i] = fact[i-1]*i%mod;
		infact[i] = infact[i-1]*qmi(i,mod-2)%mod;
	}
}

signed main(){
//	IOS;
	#ifdef ddgo
		freopen("C:/Users/asus/Desktop/ddgoin.txt","r",stdin);
	#endif
	
	int n;
	init();
	while(cin >>n)
	cout<<fact[n]*fact[n]%mod*infact[2*n+1]%mod<<endl;
	
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值