Integration
Given n distinct positive integers , find the value of
It can be proved that the value is a rational number .
Print the result as .
输入描述:
The input consists of several test cases and is terminated by end-of-file.
The first line of each test case contains an integer n.
The second line contains n integers .
*
*
* are distinct.
* The sum of does not exceed .
输出描述:
For each test case, print an integer which denotes the result.
题目大意
给定函数,求值
分析
首先,可以看出当
n
=
1
n = 1
n=1的时候,这个函数的原函数是
arctan
x
\arctan{x}
arctanx,而且很容易可以得到:
1
π
∫
0
∞
c
a
2
+
x
2
d
x
=
c
2
a
\dfrac{1}{\pi}\int_0^\infty \dfrac{c}{a^2 + x^2} \mathrm{d} x = \dfrac{c}{2a}
π1∫0∞a2+x2cdx=2ac
当
n
≥
2
n \ge 2
n≥2的时候,要想运用以上的式子,就得把连乘拆开,拆成连加的形式。
而把连乘拆开,肯定可以得到如下的形式:
1
(
a
1
2
+
x
2
)
⋅
(
a
2
2
+
x
2
)
⋅
(
a
3
2
+
x
2
)
⋯
(
a
n
2
+
x
2
)
=
c
1
a
1
2
+
x
2
+
c
2
a
2
2
+
x
2
+
c
3
a
3
2
+
x
2
+
⋯
+
c
n
a
n
2
+
x
2
\dfrac{1}{(a_1^2 + x^2)\cdot (a_2^2+x^2) \cdot (a_3^2+x^2) \cdots (a_n^2+x^2)} = \dfrac{c_1}{a_1^2+x^2} + \dfrac{c_2}{a_2^2+x^2} + \dfrac{c_3}{a_3^2+x^2} + \cdots + \dfrac{c_n}{a_n^2+x^2}
(a12+x2)⋅(a22+x2)⋅(a32+x2)⋯(an2+x2)1=a12+x2c1+a22+x2c2+a32+x2c3+⋯+an2+x2cn
那么现在问题的关键,就转变成了怎么求
c
i
c_i
ci
而 c i c_i ci的求法,可以用所谓部分分式展开法来求,示例如下:
例如,要求
c
1
c_1
c1的时候,我们可以两边乘以
a
1
2
+
x
2
a_1^2+x^2
a12+x2,得到:
a
1
2
+
x
2
(
a
1
2
+
x
2
)
⋅
(
a
2
2
+
x
2
)
⋅
(
a
3
2
+
x
2
)
⋯
(
a
n
2
+
x
2
)
=
c
1
+
c
2
a
2
2
+
x
2
⋅
(
a
1
2
+
x
2
)
+
c
3
a
3
2
+
x
2
⋅
(
a
1
2
+
x
2
)
+
⋯
+
c
n
a
n
2
+
x
2
⋅
(
a
1
2
+
x
2
)
\dfrac{a_1^2+x^2}{(a_1^2 + x^2)\cdot (a_2^2+x^2) \cdot (a_3^2+x^2) \cdots (a_n^2+x^2)} = c_1 + \dfrac{c_2}{a_2^2+x^2} \cdot (a_1^2+x^2) + \dfrac{c_3}{a_3^2+x^2} \cdot (a_1^2+x^2) + \cdots + \dfrac{c_n}{a_n^2+x^2} \cdot (a_1^2+x^2)
(a12+x2)⋅(a22+x2)⋅(a32+x2)⋯(an2+x2)a12+x2=c1+a22+x2c2⋅(a12+x2)+a32+x2c3⋅(a12+x2)+⋯+an2+x2cn⋅(a12+x2)
两边取极限,我们可以得到:(复数域)
lim
x
2
→
−
a
1
2
1
(
a
2
2
+
x
2
)
⋅
(
a
3
2
+
x
2
)
⋯
(
a
n
2
+
x
2
)
=
lim
x
2
→
−
a
1
2
c
1
+
c
2
a
2
2
+
x
2
⋅
(
a
1
2
+
x
2
)
+
c
3
a
3
2
+
x
2
⋅
(
a
1
2
+
x
2
)
+
⋯
+
c
n
a
n
2
+
x
2
⋅
(
a
1
2
+
x
2
)
\lim\limits_{x^2 \to -a_1^2}{\dfrac{1}{(a_2^2+x^2) \cdot (a_3^2+x^2) \cdots (a_n^2+x^2)}} = \lim\limits_{x^2 \to -a_1^2}{c_1 + \dfrac{c_2}{a_2^2+x^2} \cdot (a_1^2+x^2) + \dfrac{c_3}{a_3^2+x^2} \cdot (a_1^2+x^2) + \cdots + \dfrac{c_n}{a_n^2+x^2} \cdot (a_1^2+x^2)}
x2→−a12lim(a22+x2)⋅(a32+x2)⋯(an2+x2)1=x2→−a12limc1+a22+x2c2⋅(a12+x2)+a32+x2c3⋅(a12+x2)+⋯+an2+x2cn⋅(a12+x2)
也就是:
c
1
=
∏
i
=
2
n
1
(
a
i
2
−
a
1
2
)
c_1 = \prod_{i = 2}^{n}\dfrac{1}{(a_i^2-a_1^2)}
c1=i=2∏n(ai2−a12)1
同理可得:
c
i
=
∏
i
≠
j
1
(
a
j
2
−
a
i
2
)
c_i = \prod_{i \ne j}\dfrac{1}{(a_j^2-a_i^2)}
ci=i̸=j∏(aj2−ai2)1
那么函数就可以转化成
f
(
x
)
=
∑
i
=
1
n
c
i
2
a
i
f(x) = \sum_{i = 1}^{n}\dfrac{c_i}{2a_i}
f(x)=i=1∑n2aici
参考代码
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#ifdef LOCAL
#define frein(x) freopen(x, "r", stdin)
#define freout(x) freopen(x, "w", stdout)
#else
#define frein(x)
#define freout(x)
#endif
#define mem(x, v) memset(x, v, sizeof(x))
#define squ(x) ((x) * (x))
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
ll kpow(ll a, ll n){
ll ans = 1;
while(n){
if(n & 1) ans = (ans * a % mod) % mod;
a = squ(a % mod) % mod;
n >>= 1;
}
return ans;
}
ll inv(int n){
return kpow(n, mod - 2);
}
ll a[maxn];
int main(void){
frein("data.in");
//freout("data.out");
int n;
while(~scanf("%d", &n)){
for(int i = 0; i < n; i++){
scanf("%lld", &a[i]);
}
ll ans = 0;
for(int i = 0; i < n; i++){
ll t = 1;
for(int j = 0; j < n; j++){
if(i == j) continue;
t *= (squ(a[j]) % mod - squ(a[i]) % mod + mod) % mod;
t %= mod;
}
ans += inv((2 * t * a[i]) % mod);
ans %= mod;
}
printf("%lld\n", ans);
}
return 0;
}