#!/usr/bin/env ruby
# Double Squares, Facebook Hacker Cup 2011
# Kenneth Ham, <me@kennetham.com>
# http://www.kennetham.com
#
#  Double Squares
#  A double-square number is an integer X which can be expressed as the sum of two perfect squares.
#  For example, 10 is a double-square because 10 = 32 + 12.
#  Your task in this problem is, given X, determine the number of ways in which it can be written
#  as the sum of two squares. For example, 10 can only be written as 32 + 12 (we don't count 12 + 32 as being different).
#  On the other hand, 25 can be written as 52 + 02 or as 42 + 32.
#
#  Input
#  You should first read an integer N, the number of test cases. The next N lines will contain N values of X.
#  Constraints
#  0 <= X <= 2147483647
#  1 <= N <= 100
#  Output
#  For each value of X, you should output the number of ways to write X as the sum of two squares.
#
#################################################

$file = ARGV[0]
unless $file && File.exist?($file)
  puts "error: invalid file!"
  exit
end

$temp = []
$contents = IO.read $file
$_contents = $contents.split(/\n+/)
$_contents.delete_at(0)
$temp.push $_contents

def find_match(square)
  $x = square.to_i
  $x <= 2147483647
#  return 0 if $x == 0.floor
#  puts "Possible matches of #{$x}:\r\n"

  half_sqrt = Math.sqrt($x / 2)
  count = 0

  0.upto(half_sqrt) do |i|
    i_sq = (i * i)
    $n = Math.sqrt($x - i_sq)
    if (($n - $n.to_i.floor) < 0.000001)
#      puts "#{$x} = #{i.to_i}^2 + #{$n.to_i}^2\r\n"
      count += 1
    end
  end
  return count
end

$_contents.each do |j|
  puts find_match(j.to_i)
end
