1. 程式人生 > >FFT用到的各種素數

FFT用到的各種素數

bsp turn tle factor int 素數 rim logs style

技術分享

int MOD;
inline int mul(int a, int b){
    return (long long)a * b % MOD;
}
int power(int a, int b){
    int ret = 1;
    for (int t = a; b; b >>= 1){
        if (b & 1)ret = mul(ret, t);
        t = mul(t, t);
    }
    return ret;
}
int cal_root(int mod)
{
    int factor[20
], num = 0, s = mod - 1; MOD = mod--; for (int i = 2; i * i <= s; i++){ if (s % i == 0){ factor[num++] = i; while (s % i == 0)s /= i; } } if (s != 1)factor[num++] = s; for (int i = 2;; i++){ int j = 0; for (; j < num && power(i, mod / factor[j]) != 1
; j++); if (j == num)return i; } }

有用的表格

技術分享

技術分享

技術分享

詳細 http://blog.miskcoo.com/2014/07/fft-prime-table

FFT用到的各種素數