This question already has an answer here:
- Four Squares Together 14 answers
Sum of squares
Goal: Write a given natural number as sum of squares. Thanks to Lagrange, Fermat and Legendre we know that you can write any positive integer as sum of (one), two, three, or maximal four squares of integers.
Your task is to write a program/function which takes a natural number via stdin/argument and outputs/returns a list of one to four numbers, where the sum of the squares of those numbers equals the input number. But you have to find the shortest possible example, that means if you can write a number as three squares, you may not output the four squares version.
1 : 1 2 : 1,1 3 : 1,1,1 4 : 2 5 : 1,2 6 : 1,1,2 127 : 1,3,6,9 163 : 1,9,9 1234 : 3,35 1248 : 8,20,28