Some numbers can be represented as the sum of a sequence of consecutive squares; for instance, 595 = 62 + 72 + 82 + 92 + 102 + 112 + 122. Other numbers are not so representable.

Your task is to write a program that finds the longest consecutive sequence of squares that sums to a given number, or determines that no such sequence exists. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Advertisement

Pages: 1 2