def jacobi(a, n)
  raise ArgumentError.new  if n < 1 || n.even?
  res = 1
  until (a %= n) == 0
    while a.even?
      a >>= 1
      res = -res if [3, 5].include? n % 8
    end
    a, n = n, a
    res = -res if [a % 4, n % 4] == [3, 3]
  end
  n == 1? res: 0
end

puts 
puts 
puts 
1.step(to: 17, by: 2) do |n|
   printf(, n)
   (0..10).each { |a| printf(, jacobi(a, n)) }
   puts
end