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 = 3^2 + 1^2. 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 3^2 + 1^2 (we don't count 1^2 + 3^2 as being different). On the other hand, 25 can be written as 5^2 + 0^2 or as 4^2 + 3^2. 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 Output For each value of X, you should output the number of ways to write X as the sum of two squares. Now the main question is as follows , give me the program (C++ or PHP , java script or anything or even create a software if u can, 20 1022907856 148208125 2027929049 510644794 1000582589 160225 1148284322 625058908 1816371419 65 243061325 1048039120 4 542915665 415485223 25 77068225 1 2147483645 4005625 I want a software/program through which after giving the input question it will give the output
i just don't get why 10 = 32 + 12 , i'm no math genius but it doesn't make sense at all,... or did you mean 10 = 3^2 + 1^2 ?
Lol: Itz facebook Hackers cup qualification round question. now, i'm making a program for this. will post it within few hours
If you've already downloaded your input file, the time will have expired, Prateek. You only get 6 minutes from downloading the input file to upload the answer. Ruby solution is this: #!/usr/bin/env ruby # Double Squares, Facebook Hacker Cup 2011 # http://www.kennetham.com $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" halfroot = Math.sqrt($x / 2) count = 0 0.upto(halfroot) do |i| i_sq = (i * i) r = Math.sqrt($x - i_sq) if ((r - r.to_i.floor) < 0.000001) # puts "#{$x} = #{i.to_i}^2 + #{r.to_i}^2\r\n" count += 1 end end return count end $_contents.each do |j| puts find_match(j.to_i) end Code (markup):
Even quicker: guzloo.com/dsquareinput.php Upload your input file there - the source is also available.