Jacobi symbol: Difference between revisions

m (→‎{{header|REXX}}: added whitespace and comments.)
Line 266:
27 1 -1 0 1 -1 0 1 -1 0 1 -1 0 1 -1 0 1 -1 0 1 -1 0 1 -1 0 1 -1 0 1 -1 0
29 1 -1 -1 1 1 1 1 -1 1 -1 -1 -1 1 -1 -1 1 -1 -1 -1 1 -1 1 1 1 1 -1 -1 1 0 1</pre>
 
=={{header|Phix}}==
<lang Phix>function jacobi(integer a, n)
atom result = 1
a = remainder(a,n)
while a!=0 do
while remainder(a,2)==0 do
a /= 2
if find(remainder(n,8),{3,5}) then result *= -1 end if
end while
{a, n} = {n, a}
if remainder(a,4)==3 and remainder(n,4)==3 then result *= -1 end if
a = remainder(a,n)
end while
return iff(n==1 ? result : 0)
end function
 
printf(1,"n\\a 0 1 2 3 4 5 6 7 8 9 10 11\n")
printf(1," ________________________________________________\n")
for n=1 to 31 by 2 do
printf(1,"%3d", n)
for a=0 to 11 do
printf(1,"%4d",jacobi(a, n))
end for
printf(1,"\n")
end for</lang>
{{out}}
<pre>
n\a 0 1 2 3 4 5 6 7 8 9 10 11
________________________________________________
1 1 1 1 1 1 1 1 1 1 1 1 1
3 0 1 -1 0 1 -1 0 1 -1 0 1 -1
5 0 1 -1 -1 1 0 1 -1 -1 1 0 1
7 0 1 1 -1 1 -1 -1 0 1 1 -1 1
9 0 1 1 0 1 1 0 1 1 0 1 1
11 0 1 -1 1 1 1 -1 -1 -1 1 -1 0
13 0 1 -1 1 1 -1 -1 -1 -1 1 1 -1
15 0 1 1 0 1 0 0 -1 1 0 0 -1
17 0 1 1 -1 1 -1 -1 -1 1 1 -1 -1
19 0 1 -1 -1 1 1 1 1 -1 1 -1 1
21 0 1 -1 0 1 1 0 0 -1 0 -1 -1
23 0 1 1 1 1 -1 1 -1 1 1 -1 -1
25 0 1 1 1 1 0 1 1 1 1 0 1
27 0 1 -1 0 1 -1 0 1 -1 0 1 -1
29 0 1 -1 -1 1 1 1 1 -1 1 -1 -1
31 0 1 1 -1 1 1 -1 1 1 1 1 -1
</pre>
 
=={{header|Python}}==
7,830

edits