The Jacobi function returns three values: 0, if both a and n have a
divisor in common which is greater than 1; -1 if a is a QNR of n;
and +1 if a is a QR of n. Jacobi(a,n) { j := 1; while (a not 0) do { while (a even) do { a := a/2; if (n = 3 (mod 8) or n = 5 (mod 8)) then j := -j; } b := n; n := a; a := b; if (a = 3 (mod 4) and n = 3 (mod 4)) then j := -j; a := a mod n; } if (n = 1) then return (j) else return(0) }