已知 ,求 在模1e9+7意义下的值。
保证 都是正整数,并且 各不相同。
-----------------------------------------
先解里面的式子,裂项相消。
------------------------------------
所以原式等于
---------------------------------------
Code:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
ll a[1005], a2[1005];
ll power(ll a, ll b)
{
ll res = 1;
while (b)
{
if (b & 1)
res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int main()
{
int n;
while (scanf("%d", &n) > 0)
{
for (int i = 1; i <= n; i++)
{
scanf("%lld", &a[i]);
a2[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 *= (a2[j] - a2[i] + mod);
if (res >= mod)
res %= mod;
}
res = power(res, mod - 2);
ans += res;
if (ans >= mod)
ans %= mod;
}
ans = ans * power(2, mod - 2) % mod;
printf("%lld\n", ans);
}
}