给出 {qn} ,求:
FFT其实是在求向量卷积,形式是这样的:
然后我们观察题目里给的式子,会发现 j 和 i−j 和卷积很像啊QAQ,所以构造向量:
#include
#include
#include
#define fr first
#define sc second
#define mp make_pair
using namespace std;
typedef double DB;typedef pair C;
const int maxn=262144;const double pi=acos(-1);
int n,m,R[maxn+5];C f[maxn+5],F[maxn+5],g[maxn+5];
inline int Rev(int x,int len){
static int buf[31];for (int i=0;i1,x>>=1;
for (int i=0;i1|buf[i];return x;
}
C operator + (const C &a,const C &b) {return mp(a.fr+b.fr,a.sc+b.sc);}
C operator - (const C &a,const C &b) {return mp(a.fr-b.fr,a.sc-b.sc);}
C operator * (const C &a,const C &b) {return mp(a.fr*b.fr-a.sc*b.sc,a.fr*b.sc+a.sc*b.fr);}
inline void FFT(C *a,int n,int f){
for (int i=0;iif (ifor (int k=1;k1){
C w=mp(1,0),wn=mp(cos(pi/k),sin(f*pi/k)),x,y;
for (int i=0;i1,w=mp(1,0))
for (int j=0;jint main(){
freopen("program.in","r",stdin);
freopen("program.out","w",stdout);
scanf("%d",&n);n--;for (int i=1;i<=n;i++) g[i].fr=(DB)1/i/i;
for (int i=0;i<=n;i++) scanf("%lf",&f[i].fr),F[n-i]=f[i];
m=n;int len=0;for (n=1;n<=(m<<1);n<<=1) len++;for (int i=0;i1);FFT(F,n,1);FFT(g,n,1);for (int i=0;i1);FFT(F,n,-1);for (int i=0;i<=m;i++) printf("%.3f\n",(f[i].fr-F[m-i].fr)/n);
return 0;
}