Numbers With Exactly Two Square-Sum Representations
Problem statement
Given an integer n, return every integer s with 0 <= s < n that can be written as a^2 + b^2 in exactly two distinct unordered ways.
Both a and b must be nonnegative integers. Treat (a, b) and (b, a) as the same representation, so each pair is counted only with a <= b.
Return qualifying values in increasing order.
Function
numbersWithExactlyTwoSquareSums(n: int) → int[]Examples
Example 1
n = 26return = [25]25 = 0^2 + 5^2 = 3^2 + 4^2.
Example 2
n = 51return = [25,50]50 = 1^2 + 7^2 = 5^2 + 5^2, and 25 also has exactly two representations.
Example 3
n = 10return = []No value below ten has exactly two distinct unordered representations.
Constraints
1 <= n < 2^31 - 1.- The returned array may be large; its size contributes to the output cost.