Standard definition of Legendre symbol (a|b) requires that b is an odd prime. The generalization is the Kronecker symbol defined for integers b!=0:
(a|b)=Product((a|p)) where p is a prime factorization including 2 and -1 and (a|p) is the Legendre symbol. But we need these definitions:
(a|2)={0 if a is even (-1)^((a^2-1)/8) if a is odd
(a|-1)={1 if a>=0 else -1 if a<0
Note: there’s a more efficient way to calculate (-1)^((a^2-1)/8).
Lookup a mod 8 in the following table:
[0,1,0,-1,0,-1,0,1]