The first is the FFT:
An FFT is a class of transformations that transforms a polynomial of a coefficient expression into a polynomial of a point-value expression:
We want to calculate:
\ (A (x) = \sum_{j=0}^{n-1}a_{j}x^{j}\)
For n units complex roots are:
\ (Y_{k} = A (\omega _{n}^{k}) = \sum_{j = 0}^{n-1}a_{j}\omega _{n}^{kj}\)
We define
\ (A^{[0]} (x) = a_{0} + a_{2}x+a_{4}x^{2}+ \cdot \cdot \cdot +a_{n-2}x^{n/2-1}\)
\ (A^{[1]} (x) = a_{1} + a_{3}x+a_{5}x^{2}+ \cdot \cdot \cdot +a_{n-1}x^{n/2-1}\)
that \ (a^{[0]}\) contains the coefficients of all even subscript, \ (a^{[1]}\) contains the coefficients of all odd subscripts
Easy to get
\ (A (x) =a^{[0]} (X^{2}) +xa^{[1]} (X^{2})
So the question is converted to two smaller problems:
Polynomial \ (a^{[0]}\) and \ (a^{[1]}\) in points for the number of N/2
\ ((\omega _{n}^{0}) ^{2}, (\omega _{n}^{1}) ^{2},\cdot \cdot \cdot, (\omega _{n}^{n-1}) ^{2}\)
The value
Here is the code
structcpy{DoubleI, J;} A[n], B[n], c[n];cpyoperator+ (cpy A, cpy b) {return(cpy) {A.I + B.I, A.J +B.J};} cpyoperator-(cpy A, cpy b) {return(cpy) {A.I-B.I, A.J-B.J};} cpyoperator* (cpy A, cpy b) {return(cpy) {A.I * B.I-A.J * B.J, A.I * B.J + A.J *B.I};}Const DoublePI = ACOs (-1);voidFFT (cpy a[],intNintFL =1){ for(inti =1, j = (n >>1); I < n; ++i) {if(I < J) Swap (A[i], a[j]);intK; for(k = (n >>1); J & K; J ^= K, K >>=1); J ^=K; } for(inti =2; I <= N; i = i <<1) {cpy W= (cpy) {cos (fl *2* pi/i), sin (fl *2* Pi/i)}; for(intj =0; J < N; J + =i) {cpy wn= (cpy) {1,0}; for(intK = J; K < J + I/2; ++k) {cpy u= A[k], v = a[k + I/2] *WN; A[K]= U + V; A[k + I/2] = U-v; WN= WN *W; } } } if(fl <0) for(inti =0; I < n; + + i) a[i].i/=N;}
FFT
Then the NTT:
Some mathematical transformations