Three Primes And Garner

Your required modulus is 109+710^9+7, which is not NTT-friendly. How do you convolve anyway?

A

Run the NTT under 109+910^9+9, which is NTT-friendly, and adjust by the difference of the two moduli. The true coefficients are bounded by n⋅(109)2n \cdot (10^9)^2, which one modulus near 10910^9 covers, then reduce modulo 109+710^9+7 at the very end.

B

Run the NTT under three different NTT-friendly primes and recombine with the Chinese remainder theorem. The true coefficients are bounded by n⋅(109)2n \cdot (10^9)^2, which three moduli near 10910^9 cover, then reduce modulo 109+710^9+7 at the very end.

C

Run the NTT under one NTT-friendly prime and lift the result with Hensel's lemma. The true coefficients are bounded by n⋅(109)2n \cdot (10^9)^2, which one modulus near 10910^9 pins down, then reduce modulo 109+710^9+7 at the very end.

D

Run a plain double-precision FFT directly on the coefficients and round. The rounding error stays below 0.50.5 for any nn and any coefficient size, which one transform covers, then reduce modulo 109+710^9+7 at the very end.