In November 2019, Alon Ran published a particularly lovely sequence in the OEIS, A329126:
\$a(n)\$ is the lexicographically earliest string of digits which yields a multiple of \$n\$ when read in any numeric base.
1, 110, 101010, 111100, 100010001000100010, 1111110, 10000010000010000010000010000010000010, 11111111000, 1010101010101010100, ...
For example, \$a(3) = 101010\$ because this is the smallest number that is a multiple of \$3\$ in every integer base $$ \begin{alignat}{2} 101010_1 &= 1^5 + 1^3 + 1^1 = 3 &&= 3\cdot1 \\ 101010_2 &= 2^5 + 2^3 + 2^1 = 42 &&= 3\cdot14 \\ 101010_3 &= 3^5 + 3^3 + 3^1 = 273 &&= 3\cdot91 \\ 101010_4 &= 4^5 + 4^3 + 4^1 = 1092 &&= 3\cdot364 \\ 101010_5 &= 5^5 + 5^3 + 5^1 = 3255 &&= 3\cdot1085 \\ &\hspace{0.4em}\vdots \end{alignat} $$ Another way of conceptualizing this is that the polynomial \$f(n) = n^5 + n^3 + n\$ is divisible by \$3\$ for every integer \$n\$, which you can check manually with modular arithmetic.
We can generalize this idea further by looking at polynomials with restricted coefficients. For example, if we allow the coefficients of the polynomial to be \$\{-1,0,1\}\$, then \$g(n) = n^4-n^2\$ is divisible by \$4\$ for all integers \$n\$.
The challenge!
In any reasonable format of your choosing, you will be given a list of allowed integer coefficients, coefficients
(which always contains both \$0\$ and \$1\$), and a positive integer, k
.
Your job is to find the degree, d
, of the smallest monic polynomial as measured by degree, $$
p(n) = n^d + c_{d-1}n^{d-1} + \dots + c_2n^2 + c_1n + c_0,
$$ such that each \$c_i\$ is in coefficients
and \$p(n)\$ is a multiple of \$k\$ for all integers \$n \in \mathbb{Z}\$.
In order to avoid the simplest form of brute-forcing, your program must be able to compute each individual test case from the test data on TIO (or, if TIO does not support your language, on my machine within 60 seconds). This is code-golf, so shortest code wins.
Test data
coefficients | k | d | example
-------------+---+----+--------------------------------------------
[0,1] | 1 | 0 | 1
[0,1] | 2 | 2 | x^2 + x
[0,1] | 3 | 5 | x^5 + x^3 + x
[0,1] | 4 | 5 | x^5 + x^4 + x^3 + x^2
[0,1] | 5 | 17 | x^17 + x^13 + x^9 + x^5 + x
[0,1] | 6 | 6 | x^6 + x^5 + x^4 + x^3 + x^2 + x
[0,1] | 7 | 37 | x^37 + x^31 + x^25 + x^19 + x^13 + x^7 + x
[-1,0,1] | 4 | 4 | x^4 - x^2
[-1,0,1] | 5 | 5 | x^5 - x
[-1,0,1] | 6 | 3 | x^3 - x
[-1,0,1] | 7 | 7 | x^7 - x
[-1,0,1] | 8 | 5 | x^5 - x^3
[-1,0,1] | 9 | 8 | x^8 - x^6 - x^4 + x^2
[ 0,1,2] | 4 | 4 | x^4 + x^2 + 2x
[ 0,1,3] | 5 | 9 | x^9 + x^5 + 3x
[ 0,1,2,3] | 6 | 3 | x^3 + 3x^2 + 2x