%I #27 Aug 08 2023 18:04:30
%S 2,5,3,2,2,3,10,2,7,9,12,11,6,11,14,3,11,29,14,7,23,4,49,8,24,5,17,12,
%T 38,46,27,34,6,14,22,66,11,66,14,11,6,77,36,63,96,11,50,3,19,96,52,41,
%U 66,33,11,3,14,121,66,89,34,127,51,2,86,54,181,48,8
%N a(n) is the minimal number of consecutive squares needed to sum to A216446(n).
%H Project Euler, <a href="https://projecteuler.net/problem=125">Problem 125: Palindromic Sums</a>.
%e a(8) = 7 is because 7 consecutive squares are needed to sum to A216446(8) = 595 = 6^2 + 7^2 + 8^2 + 9^2 + 10^2 + 11^2 + 12^2.
%o (Python)
%o is_palindrome = lambda n: str(n) == str(n)[::-1]
%o def g(L):
%o L2, squares, D = L*L, [x*x for x in range(0, L + 1)], {}
%o for i in range(1, L + 1):
%o for j in range(i + 1, L + 1):
%o candidate = sum(squares[i:j+1])
%o if candidate < L2 and is_palindrome(candidate):
%o if candidate in D:
%o D[candidate]= min(D[candidate], j-i-1)
%o else:
%o D[candidate] = j-i+1
%o return [D[k] for k in sorted(D.keys())]
%o print(g(1000))
%Y Cf. A216446, A034705, A180436, A267600.
%K nonn,base
%O 1,1
%A _DarĂo Clavijo_, Jul 10 2023