Project Euler 125 - Palindromic Sums

Official link: https://projecteuler.net/problem=125

Thought Process

Generate the maximum n possible that is 1^2 + ... + n^2 < 10^8 (max-n = 668)

A consecutive square number must be of the form a^2 + (a+1)^2 = 2a^2 + 2a + 1, therefore the biggest a possible is

2a^2 + 2a + 1 = 10^8 => 2a^2 + 2a + (1-10^8) = 0 use quadratic formula to find maximum a, max-a = 7070


Create a double nested loop as follows:

for a from 1 to max-a:
tempsum = a^2
for n from a to max-n:
tempsum += (a+n)^2

Like this we continually create sum of consecutive squares, we then check if tempsum > 10^8 or if tempsum is a palindrome

Make sure to remove duplicates at the end!

Interactive Code

Enter a number (yourinput)

Code will output the sum of all numbers less than yourinput that are both palindromic and can be written as the sum of consecutive squares