Using the FFT Algorithm to Compute

Given a set of n particles, charged charge carriers are found at points (1,0), (2,0), ... (n, 0) on the plane. The particle charge found at the point (i, 0) is marked as Qi. the force acting on the particle is determined by the formula:

enter image description here C is the Coulomb constant.

Give an algorithm to calculate Fi for all particles with a total of O (nlgn). Hint: use the FFT algorithm.

It seems that Fi is already divided into even and odd points.

I thought about splitting each sum to calculate the FFT (but divide until ...?) And then always always add up half the points (because that's what the FFT causes) and then subtract the result of the sums given according to the formula.

any idea how to make it better?

+2
1

, , .
FFT - :

  • 2

    ( )

  • FFT-

    , 2 ( ) , . dataset size<=1 2, , , .

    ,

, NTT (- )

//---------------------------------------------------------------------------
void fourier_NTT:: NTT_fast(DWORD *dst,DWORD *src,DWORD n,DWORD w)
    {
    // recursion stop condition if the data is single number ...
    if (n<=1) { if (n==1) dst[0]=src[0]; return; }
    DWORD i,j,a0,a1,n2=n>>1,w2=modmul(w,w);
    // reorder even,odd to dst array
    for (i=0,j=0;i<n2;i++,j+=2) dst[i]=src[j];
    for (    j=1;i<n ;i++,j+=2) dst[i]=src[j];
    // recursion
    NTT_fast(src   ,dst   ,n2,w2);  // even
    NTT_fast(src+n2,dst+n2,n2,w2);  // odd
    // restore results
    for (w2=1,i=0,j=n2;i<n2;i++,j++,w2=modmul(w2,w))
        {
        a0=src[i];
        a1=modmul(src[j],w2);
        dst[i]=modadd(a0,a1);
        dst[j]=modsub(a0,a1);
        }
    }
//---------------------------------------------------------------------------

.

!!!

.

NTT :

//---------------------------------------------------------------------------
void fourier_NTT:: NTT_slow(DWORD *dst,DWORD *src,DWORD n,DWORD w)
    {
    DWORD i,j,wj,wi,a,n2=n>>1;
    for (wj=1,j=0;j<n;j++)
        {
        a=0;
        for (wi=1,i=0;i<n;i++)
            {
            a=modadd(a,modmul(wi,src[i]));
            wi=modmul(wi,wj);
            }
        dst[j]=a;
        wj=modmul(wj,w);
        }
    }
//---------------------------------------------------------------------------

[]

  • , 2- , , .

+1

All Articles