Thinking about it, I accepted two things. The first is that for any a ^ 2 + b ^ 2 a> b. This is simply because it is trivial (a, b) to be in the same place in order like (b, a), so you do not need to consider both.
The explanation is also simpler if a or b is allowed equal to 0. These cases can be easily extracted in a real algorithm.
My thinking is that you have to do something based on looking at m=a+b and stating that for a given m, the smallest sum of squares is m^2/2 (when they are equal), and the largest is (m-1)^2 with an obvious order between them. Then you can do a sort sort between them to find the next one.
I think that if you look at m=a+b , then for any given m you can create an ordered list of sums of squares for all a+b=m . The reason is that we know that the sum is maximum when a or b is 0 and minimum when a=b=m/2 . This means that we can trivially generate a series of lists of ordered sums of squares L(m) .
We also know the maximum and minimum entries in L (m), so we don’t need to start looking at these lists until we are in this range.
This will still mean potentially a lot to consider at higher values, but it is still better than a rougher approach.
I am not sure if there is a better way if you have this list, although in order to decide which one you need to choose. I think this is probably not true, although you could make some guesses based on the distribution of numbers in lists, but I cannot think of a way to formalize them in a good way.
To give a clearer example of things, then
List Lowest value Highest value L(0) 0 (0,0) 0 (0,0) L(1) 1 (1,0) 1 (1,0) L(2) 2 (1,1) 4 (2,0) L(3) 5 (2,1) 9 (3,0) L(4) 8 (2,2) 16 (4,0) L(5) 13 (3,2) 25 (5,0) L(6) 18 (3,3) 36 (6,0) L(7) 25 (4,3) 49 (7,0) L(8) 32 (4,4) 64 (8,0)
So, to start from 0, you only need to consider the elements in L (0), then this is exhausted, and you go to L (1). Then it is exhausted, etc. Then, working through L (3), you will find that you are looking at the last of L (3), which is larger than the lowest in L (4), so you are looking at both of these lists.
When you just put (5.0) and (4.3) over 25, you will consider things in L (6) and L (7). As you go higher, you will consider more lists as lists begin to contain more items in a larger range (for example, the number 10,000 is in the range for L (100) (approximately) and L (141) (which starts with 9941).
I should also note that you do not need to pre-compute the entire list, you can easily make it a lazy iterator to only calculate the number in front of the list, as this is the only one you ever wanted.