Jacobi symbol: Difference between revisions
→{{header|jq}}: ce
(→{{header|jq}}: ce) |
|||
Line 818:
def jacobi(a; n):
{a: (a % n), n: n, result: 1}
| until(
until( .a % 2 != 0;
.a /= 2
| if (.n % 8) | IN(3, 5) then .result *= -1 else . end )
| (.n % 4) as $nmod4
| if (.a % 4) == $nmod4 and $nmod4 == 3 then .
| .a = .a % .n )
" Table of jacobi(a; n)",
Line 856 ⟶ 855:
29 1 -1 -1 1 1 1 1 -1 1 -1 -1 -1
31 1 1 -1 1 1 -1 1 1 1 1 -1 -1</pre>
=={{header|Julia}}==
{{trans|Python}}
|