Calculate the Kronecker symbol Relevant links here and here, but here is the short version:
You have an input of two integers \$a\$ and \$b\$ between negative infinity and infinity (though if necessary, I can restrict the range, but the function must still accept negative inputs).
Definition of the Kronecker symbol
You must return the Kronecker symbol \$(a|b)\$ for inputs \$a\$ and \$b\$ where
$$(a|b) = (a|p_1)^{e_1} \cdot (a|p_2)^{e_2} \cdots (a|p_n)^{e_n}$$
where \$b = p_1^{e_1} \cdot p_2^{e_2} \cdots p_n^{e_n}\$, and \$p_i\$ and \$e_i\$ are the primes and exponents in the prime factorization of \$b\$.

For an odd prime \$p\$, \$(a|p)=a^{\frac{p-1}2} \mod p\$ as defined here.

For \$b = 2\$,


$$
(n|2) = \begin{cases}
0    &amp; \text{if } n \equiv   0   \mod 2 \\
1    &amp; \text{if } n \equiv \pm 1 \mod 8 \\
-1   &amp; \text{if } n \equiv \mp 3 \mod 8
\end{cases}
$$

For \$b = -1\$,

$$
(n|-1) = \begin{cases}
-1 &amp; \text{if } n  &lt;  0 \\
1  &amp; \text{if } n \ge 0
\end{cases}
$$

If \$a \ge b\$, \$(a|b) = (z|b)\$ where \$z = a\mod b\$. By this property, and as explained here and here, \$a\$ is a quadratic residue of \$b\$ if \$z\$ is, even though \$a \ge b\$.

\$(-1|b) = 1\$ if \$b \equiv 0,1,2 \mod 4\$ and \$-1\$ if \$b = 3 \mod 4\$.

\$(0|b)\$ is \$0\$ except for \$(0|1)\$ which is \$1\$, because \$(a|1)\$ is always \$1\$ and for negative \$a\$, \$(-a|b) = (-1|b) \times (a|b)\$.


The output of the Kronecker symbol is always \$-1, 0 \text{ or } 1\$, where the output is \$0\$ if \$a\$ and \$b\$ have any common factors. If \$b\$ is an odd prime, \$(a|b) = 1\$ if \$a\$ is a quadratic residue \$\mod b\$, and \$-1\$ if is it is not a quadratic residue.
Rules

Your code must be a program or a function.

The inputs must be in the order a b.

The output must be either \$-1, 0 \text{ or } 1\$.

This is code golf, so your code does not have to be efficient, just short.

No built-ins that directly calculate the Kronecker or the related Jacobi and Legendre symbols. Other built-ins (for prime factorization, for example) are fair game.


Examples
&gt;&gt;&gt; kronecker(1, 5)
1
&gt;&gt;&gt; kronecker(3, 8)
-1
&gt;&gt;&gt; kronecker(15, 22)
1
&gt;&gt;&gt; kronecker(21, 7)
0
&gt;&gt;&gt; kronecker(5, 31)
1
&gt;&gt;&gt; kronecker(31, 5)
1
&gt;&gt;&gt; kronecker(7, 19)
1
&gt;&gt;&gt; kronecker(19, 7)
-1
&gt;&gt;&gt; kronecker(323, 455625)
1
&gt;&gt;&gt; kronecker(0, 12)
0
&gt;&gt;&gt; kronecker(0, 1)
1
&gt;&gt;&gt; kronecker(12, 0)
0
&gt;&gt;&gt; kronecker(1, 0)
1
&gt;&gt;&gt; kronecker(-1, 5)
1
&gt;&gt;&gt; kronecker(1, -5)
1
&gt;&gt;&gt; kronecker(-1, -5)
-1
&gt;&gt;&gt; kronecker(6, 7)
-1
&gt;&gt;&gt; kronecker(-1, -7)
1
&gt;&gt;&gt; kronecker(-6, -7)
-1

This is a complicated function, so please let me know if anything is unclear.
Python 3, 747 369 335 bytes

As an example answer, only slightly golfed, and to give you an idea of what an answer will look like.
And yes, the prime factorization and run-length-encoding bits are cribbed from Pyth with apologies to isaacg.
from itertools import*
def k(d,r):
 if d&lt;0:a=-d;m=1
 else:a=d;m=0
 if r==1:return 1
 p=1;w=r;n=2;f=[]
 while n*n&lt;=w:
  while w%n&lt;1:w//=n;f+=n,
  n+=1
 if w&gt;1:f+=w,
 z=[[k,len(list(g))]for k,g in groupby(f)]
 for i,j in z:
  if i==2:p*=pow(-1,(a*a-1)//8)
  x=pow(a,(i-1)//2,i)
  if x&gt;1:x-=i
  p*=x**j
 if m:p*=pow(-1,(r-1)//2)
 return p