The Length Ceiling
You convolve two arrays of length 6⋅106 each, modulo 998244353. What goes wrong?
The result has about 1.2⋅107 coefficients and needs transform length 224, but p−1 is divisible by only 223, so no primitive 224-th root of unity exists. Move to a prime with a bigger power of two, such as 1004535809=479⋅221+1, or split the convolution.
The result has about 1.2⋅107 coefficients and needs transform length 224, but p−1 is divisible by only 223, so no primitive 224-th root of unity exists. Move to a prime with a bigger power of two, such as 469762049=7⋅226+1, or split the convolution.
The result has about 1.2⋅107 coefficients and needs transform length 224, and p−1 is divisible by 226, so a primitive 224-th root of unity does exist. The transform length depends on the array lengths alone, never on the modulus.
The result has about 1.2⋅107 coefficients and needs transform length 224, but the 64-bit butterfly product overflows at that length, so the roots of unity lose precision. Switch the accumulator to __int128, which restores the exact result at any transform length.
Sign in to answer questions and track your progress
Sign In