题目链接:https://ac.nowcoder.com/acm/contest/881/B
题解:裂项相消,
以此类推,对于每一项,都是这样的形式,分母上常数项 是其他项的系数减去该项的系数 的乘积
积分化简 :
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int N = 1e3 + 10;
ll a[N];
int n;
ll ksm(ll x, ll y) {
ll res = 1;
while(y) {
if(y & 1) res = res * x % mod;
y >>= 1;
x = x * x % mod;
}
return res;
}
int main() {
ll ans, cnt;
while(~scanf("%d", &n)) {
for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);
ans = 0;
for(int i = 1; i <= n; i++) {
cnt = 1;
for(int j = 1; j <= n; j++) {
if(i == j) continue;
cnt = cnt * ( (a[j] * a[j] - a[i] * a[i]) % mod ) % mod;
}
ans = (ans + ksm(cnt, mod - 2) * ksm(a[i] * 2, mod - 2) % mod) % mod;
}
printf("%lld\n", (ans % mod + mod ) % mod);
}
return 0;
}