Integration(定积分)
作者:互联网
链接:https://ac.nowcoder.com/acm/contest/881/B
来源:牛客网
裂项,化乘为加
以此类推
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<list>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll a[1005];
int n;
ll ksm(ll a,ll b){
ll s=1;
while(b){
if(b&1){
s%=mod;
a%=mod;
s*=a;
}
a%=mod;
a*=a;
b>>=1;
}
return s%=mod;
}
ll k(int x){
ll ans=1;
for(int i=1;i<=n;i++){
if(i!=x){
ans*=(a[i]*a[i]-a[x]*a[x])%mod;
ans=(ans%mod+mod)%mod;
}
}
return ans;
}
int main(){
while(~scanf("%d",&n)){
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
ll ans=0;
for(int i=1;i<=n;i++){
ans+=ksm(k(i)*(a[i]<<1)%mod,mod-2)%mod;
ans%=mod;
}
printf("%lld\n",ans);
}
return 0;
}
标签:int,积分,ll,Integration,long,include,s%,mod 来源: https://blog.csdn.net/qq_42936517/article/details/96482083