%I #19 Oct 21 2024 18:26:43
%S 2,3,6,21,15,91,246,429,1005,399,3094,3045,21099,41155,43059,404754,
%T 214230,569130,182919,2190279,860574,9361374,8042479,33440551,
%U 36915670,11993466,287638530,182528031,697126530,78278655,3263415285,6941299170,25856763139,32968406926,13803374706
%N a(n) is the least number k that is not a quadratic residue modulo prime(n) but is a quadratic residue modulo all previous primes.
%C a(n) = A000037(j) for the least j such that A144294(j) = prime(n).
%C Such numbers k exist for all n >= 2: for example, if x is a quadratic nonresidue modulo prime(n), by the Chinese Remainder Theorem there exists k such that k == x (mod prime(n)) and k == 1 (mod prime(j)) for 1 <= j < n.
%e a(4) = 6 because 6 is not a quadratic residue modulo 7, but is a quadratic residue modulo 2, 3, and 5, and no smaller number works.
%p f:= proc(n) local k,p;
%p if issqr(n) then return -1 fi;
%p p:= 1;
%p for k from 1 do
%p p:= nextprime(p);
%p if numtheory:-quadres(n,p) = -1 then return k fi
%p od
%p end proc:
%p V:= Array(2..32): count:= 0:
%p for k from 2 while count < 31 do
%p v:= f(k);
%p if v > 0 and v <= 32 and V[v] = 0 then
%p V[v]:= k; count:= count+1
%p fi
%p od:
%p convert(V,list);
%o (Python)
%o from itertools import count
%o from math import isqrt
%o from sympy.ntheory import prime, nextprime, legendre_symbol
%o def A377212(n):
%o p = prime(n)
%o for r in count(1):
%o k, q = r+(m:=isqrt(r))+(r>=m*(m+1)+1), 2
%o while (q:=nextprime(q)):
%o if q>p or legendre_symbol(k,q)==-1:
%o break
%o if p==q:
%o return k # _Chai Wah Wu_, Oct 20 2024
%Y Cf. A000037, A096636, A144294, A144295.
%K nonn
%O 2,1
%A _Robert Israel_, Oct 19 2024
%E a(33)-a(36) from _Chai Wah Wu_, Oct 21 2024