OFFSET
0,7
EXAMPLE
a(8) = 2: +1^2 - 2^2 - 3^2 + 4^2 - 5^2 + 6^2 + 7^2 - 8^2 =
-1^2 + 2^2 + 3^2 - 4^2 + 5^2 - 6^2 - 7^2 + 8^2 = 0.
MAPLE
b:= proc(n, i) option remember; `if`(n>i*(i+1)*(2*i+1)/6, 0,
`if`(i=0, 1, b(n+i^2, i-1)+b(abs(n-i^2), i-1)))
end:
a:=n-> b(0, n)+b(1, n):
seq(a(n), n=0..42); # Alois P. Heinz, Jan 16 2022
MATHEMATICA
b[n_, i_] := b[n, i] = If[n > i*(i + 1)*(2*i + 1)/6, 0,
If[i == 0, 1, b[n + i^2, i - 1] + b[Abs[n - i^2], i - 1]]];
a[n_] := b[0, n] + b[1, n];
Table[a[n], {n, 0, 42}] (* Jean-François Alcover, Mar 01 2022, after Alois P. Heinz *)
PROG
(Python)
from itertools import product
def a(n):
if n == 0: return 1
nn = ["0"] + [str(i)+"**2" for i in range(1, n+1)]
return sum(eval("".join([*sum(zip(nn, ops+("", )), ())])) in {0, 1} for ops in product("+-", repeat=n))
print([a(n) for n in range(18)]) # Michael S. Branicky, Jan 16 2022
(Python)
from functools import cache
@cache
def b(n, i):
if n > i*(i+1)*(2*i+1)//6: return 0
if i == 0: return 1
return b(n+i**2, i-1) + b(abs(n-i**2), i-1)
def a(n): return b(0, n) + b(1, n)
print([a(n) for n in range(43)]) # Michael S. Branicky, Jan 16 2022 after Alois P. Heinz
CROSSREFS
KEYWORD
nonn
AUTHOR
Ilya Gutkovskiy, Dec 29 2021
STATUS
approved