牛客多校第一场 B.Integration

Integration

传送门

Bobo knows that

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.
示例1

输入

复制
1
1
1
2
2
1 2

输出

复制
500000004
250000002
83333334

题目大意

给定函数,求值

分析

首先,可以看出当 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} π10a2+x2cdx=2ac
n ≥ 2 n \ge 2 n2的时候,要想运用以上的式子,就得把连乘拆开,拆成连加的形式。
而把连乘拆开,肯定可以得到如下的形式:
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)} x2a12lim(a22+x2)(a32+x2)(an2+x2)1=x2a12limc1+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=2n(ai2a12)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(aj2ai2)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=1n2aici

参考代码

#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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值