2019牛客暑期多校训练营(第一场)B.Integration(留数定理)
题目大意
总所周知
∫
0
∞
1
1
+
x
2
d
x
=
π
2
\int_0^{\infty}\frac{1}{1+x^2}dx=\frac{\pi}{2}
∫0∞1+x21dx=2π
,现求
1
π
∫
0
∞
1
∏
i
=
1
n
(
a
i
2
+
x
2
)
d
x
\frac{1}{\pi}\int_0^\infty\frac{1}{\prod_{i=1}^n(a_i^2+x^2)}dx
π1∫0∞∏i=1n(ai2+x2)1dx
解题思路
对原式进行裂项,根据留数定理,第j项就是
1
π
∏
i
=
1
n
&
&
i
!
=
j
(
a
i
2
−
a
j
2
)
∫
0
∞
1
a
j
2
+
x
2
d
x
\frac{1}{\pi\prod_{i=1}^{n\&\&i!=j}(a_i^2-a_j^2)}\int_0^\infty\frac{1}{a_j^2+x^2}dx
π∏i=1n&&i!=j(ai2−aj2)1∫0∞aj2+x21dx
而
∫
0
∞
1
a
j
2
+
x
2
d
x
=
π
2
a
j
\int_0^\infty\frac{1}{a_j^2+x^2}dx=\frac{\pi}{2a_j}
∫0∞aj2+x21dx=2ajπ
则可以得出答案
AC代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod =1e9+7;
const int size=1e3+5;
int quick_pow(int a,int b)
{
int ans=1;
while(b)
{
if(b&1) ans=1LL*ans*a%mod;
a=1LL*a*a%mod;
b>>=1;
}
return ans%mod;
}
int a[size];
int k[size];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=1;i<=n;i++)
{
k[i]=1;
for(int j=1;j<=n;j++)
{
if(j==i) continue;
k[i]=1LL*k[i]*((1LL*a[j]*a[j]%mod-1LL*a[i]*a[i]%mod+mod)%mod)%mod;
}
k[i]=quick_pow(k[i],mod-2);
}
int ans=0;
for(int i=1;i<=n;i++)
{
ans=(ans+1LL*k[i]*500000004%mod*quick_pow(a[i],mod-2)%mod)%mod;
}
printf("%d\n",ans);
}
}