2019牛客第一场-B题Integration-高数

在这里插入图片描述
在这里插入图片描述
AC 代码:
题解且听大佬详解:https://www.cnblogs.com/Dillonh/p/11209476.html?tdsourcetag=s_pcqq_aiomsg(转载)

#include<bits/stdc++.h>
// #include<iostream>
// #include<cstdio>
// #include<vector>
// #include<cstring>
using namespace std;
#define per(i,a,b) for(int i = (a);i <= (b);++i)
#define rep(i,a,b) for(int i = (a);i >= (b);--i)
typedef long long LL;
const int maxn = 2e5 + 10;
const LL mod = (1e9 + 7);
#define INF 0x3f3f3f
typedef long long LL;
int n = 0;
LL a[maxn];
LL q_pow(LL x,LL y,LL mod){
	LL res = 1;
	while(y){
		if(y&1){
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
void solve(){
	LL p2 = q_pow(2,mod-2,mod);//求2的逆元
	LL cnt[maxn];
	per(i,1,n){
		cnt[i] = 1;
		per(j,1,n){
			if(i == j){
				continue;
			}
			cnt[i] = cnt[i] * (a[j]*a[j]%mod - a[i]*a[i]%mod) % mod;
		}
		cnt[i] = q_pow(cnt[i],mod-2,mod);
		cnt[i] = cnt[i] * q_pow(a[i],mod-2,mod) % mod;
		cnt[i] = cnt[i] * p2 % mod;
	}

	LL ans = 0;
	per(i,1,n){
		ans = ((ans + cnt[i]) % mod + mod) % mod;//cnt[i]可能为负数
	}
	printf("%lld\n",ans);

}
int main(){
	while(~scanf("%d",&n)){
		per(i,1,n){
			scanf("%lld",&a[i]);
		}
		solve();
	}


	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值