FFT
把 qi 除掉之后,发现所有 Ei 的形式很有趣,都差不多,而且像卷积。考虑构造两个多项式来满足 Ei 的答案就是两个多项式相乘的第 i 个系数,乱构一下然后FFT即可。
#include<cmath>
#include<cstdio>
#include<algorithm>
#define N 400005
using namespace std;
namespace runzhe2000
{
typedef long double ld;
struct com
{
ld r, i;
com operator + (const com &that) const {return (com){r+that.r, i+that.i};}
com operator - (const com &that) const {return (com){r-that.r, i-that.i};}
com operator * (const com &that) const {return (com){r*that.r-i*that.i, r*that.i+i*that.r};}
}w[N],re_w[N],a[N],b[N];
int n; ld ans[N], A[N], B[N];
void init_w()
{
const ld pi = acos(-1.0);
for(int i = 0; i < n; i++)
{
w[i] = (com){cos(2*pi*i/n), sin(2*pi*i/n)};
re_w[i] = (com){cos(2*pi*i/n), -sin(2*pi*i/n)};
}
}
void FFT(com *a, com *w)
{
for(int i = 0, j = 0; i < n; i++)
{
if(i > j) swap(a[i], a[j]);
for(int l = n>>1; (j^=l) < l; l >>= 1);
}
for(int i = 2; i <= n; i <<= 1)
{
int m = i >> 1;
for(int j = 0; j < n; j += i)
for(int k = 0; k < m; k++)
{
com tmp = a[j+k+m] * w[n/i*k];
a[j+k+m] = a[j+k] - tmp;
a[j+k] = a[j+k] + tmp;
}
}
}
void main()
{
scanf("%d",&n);
for(int i = 1; i <= n; i++) scanf("%Lf",&A[i]), B[i] = 1.0/i/i;
int tmp = n; for(n=1; n<=tmp+tmp; n<<=1); init_w();
for(int i = 0; i < N; i++) a[i].r = a[i].i = b[i].r = b[i].i = 0;
for(int i = 1; i <= tmp; i++) a[i].r = A[i], b[i].r = B[i];
FFT(a, w); FFT(b, w); for(int i = 0; i < n; i++) a[i] = a[i] * b[i]; FFT(a, re_w);
for(int i = 1; i <= tmp; i++) ans[i] += a[i].r / n;
for(int i = 0; i < n; i++) a[i].r = a[i].i = b[i].r = b[i].i = 0;
for(int i = 1; i <= tmp; i++) a[i].r = A[tmp-i+1], b[i].r = B[i];
FFT(a, w); FFT(b, w); for(int i = 0; i < n; i++) a[i] = a[i] * b[i]; FFT(a, re_w);
for(int i = 1; i <= tmp; i++) ans[i] -= a[tmp-i+1].r / n;
for(int i = 1; i <= tmp; i++) printf("%.3lf\n",(double)(ans[i]+1e-8));
}
}
int main()
{
runzhe2000::main();
}