参考了Keven的题解
https://blog.nowcoder.net/n/593dcc7e9edb47e291aa5e7371f685d6
题意
给个公式
求答案
自己手推了一下
这个分母很大,我们对每个分母都求逆元,再用乘法求出这些逆元的积,最后再求一下逆元就是答案,计算过程中注意模。
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3 + 5;
const ll mod = 1e9 + 7;
ll a[maxn];
ll a_pow[maxn];
ll quick_pow(ll a,ll b)//快速幂
{
ll ans = 1;
while(b)
{
if(b & 1)
ans = (ans * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return ans;
}
int main()
{
int n;
while(scanf("%d", &n) != EOF)
{
for(int i = 1; i <= n ; i++)
{
scanf("%lld", &a[i]);
a_pow[i] = a[i] * a[i] % mod;
}
ll ans = 0;
for(int i = 1; i <= n; i++)
{
ll res = a[i];
for(int j = 1 ;j <= n; j++)
{
if(i == j)//跳过
continue;
res = res * (a_pow[j] - a_pow[i] + mod) % mod;//分母逆元累积
}
ans = (ans + quick_pow(res, mod - 2)) % mod;//累加
}
ans = ans * quick_pow(2, mod - 2) % mod;//乘二的逆元
printf("%lld\n", ans);
}
return 0;
}