Data Structures & AlgorithmsHardProduct Company SDE · CP practice

Problem: How many integer solutions (x, y) satisfy x^2 + y^2 = 65 with x, y >= 0? Run the code.

Problem: How many integer solutions (x, y) satisfy x^2 + y^2 = 65 with x, y >= 0? Run the code.
print(sum(1 for x in range(0, 9) for y in range(0, 9) if x * x + y * y == 65))
What is printed?
  1. A. 5
  2. B. 3
  3. C. 6
  4. D. 4

Correct answer: D. 4

The representations of 65 as sums of two squares are 1^2 + 8^2 and 4^2 + 7^2, giving the ordered pairs (1,8), (8,1), (4,7), (7,4).

More Coding Interview Problems questions

Exams that ask this topic