The Length Ceiling

You convolve two arrays of length 6⋅1066 \cdot 10^6 each, modulo 998244353998244353. What goes wrong?

A

The result has about 1.2⋅1071.2 \cdot 10^7 coefficients and needs transform length 2242^{24}, but p−1p - 1 is divisible by only 2232^{23}, so no primitive 2242^{24}-th root of unity exists. Move to a prime with a bigger power of two, such as 1004535809=479⋅221+11004535809 = 479 \cdot 2^{21} + 1, or split the convolution.

B

The result has about 1.2⋅1071.2 \cdot 10^7 coefficients and needs transform length 2242^{24}, but p−1p - 1 is divisible by only 2232^{23}, so no primitive 2242^{24}-th root of unity exists. Move to a prime with a bigger power of two, such as 469762049=7⋅226+1469762049 = 7 \cdot 2^{26} + 1, or split the convolution.

C

The result has about 1.2⋅1071.2 \cdot 10^7 coefficients and needs transform length 2242^{24}, and p−1p - 1 is divisible by 2262^{26}, so a primitive 2242^{24}-th root of unity does exist. The transform length depends on the array lengths alone, never on the modulus.

D

The result has about 1.2⋅1071.2 \cdot 10^7 coefficients and needs transform length 2242^{24}, 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.