Find smallest prime $p$ such that all primes $q < 40$ are quadratic non-residues $\pmod p$

elementary-number-theoryprime numbersquadratic-residues

What is the smallest prime $p$ such that every prime $q < 40$ is a quadratic non-residue $\pmod p$? Given that the probability that $q$ is a non-residue mod $\pmod p$ is $1/2$, and there are $12$ primes less than $40$, I would expect at least checking $4,096$ primes before finding one that meets the conditions.

Best Answer

This is just a tiny bit more involved than Wolfram Alpha can handle:

Select[Prime[Range[100]], Union[JacobiSymbol[Prime[Range[12]], #]] == {-1} &]

The answer is $163$. You could have gotten the answer a lot quicker if you had just asked a wood nymph.

Oh, right, you don't know how to talk to wood nymphs. Okay, so if in Mathematica you change 100 to 4096, the only answer is $163$. However, go up a little higher to find $74093$.

Why so few? That might be a more interesting question. Or not.