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 <bits/stdc++.h>
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;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值