2019牛客暑期多校训练营(第一场)B Integration 裂项相消 + 积分

题目链接:https://ac.nowcoder.com/acm/contest/881/B

 

 

题解:裂项相消,

\frac{1}{(x^2+a^2)(x^2+b^2)(x^2+c^2)} = \frac{1}{(b^2-a^2)(c^2-a^2)(x^2+a^2)}+\frac{1}{(a^2-b^2)(c^2-b^2)(x^2+b^2)}+\frac{1}{(a^2-c^2)(b^2-c^2)(x^2+c^2)}

以此类推,对于每一项,都是这样的形式,分母上常数项 是其他项的系数减去该项的系数 的乘积

积分化简 : \int_{0}^{\infty } \frac{1}{x^{2}+a^{2}}dx = \frac{\pi }{2a}

 

#include 
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;
}

 

你可能感兴趣的:(数学)