OFFSET
1,2
COMMENTS
Theorem: Every positive integer is a sum of at most four distinct quarter squares (proved at Math Overflow link). The greedy representation is found as follows. Let f(n) be the greatest quarter-square <= n, and apply r(n) = f(n) + r(n - f(n)) until reaching 0. The least term of r(n) is the trace of n, at A257022.
LINKS
EXAMPLE
The array:
0 1 2 4 6 9 12 ...
3 5 7 8 10 11 13 ...
15 19 23 28 33 35 39 ...
255 271 287 304 321 339 357 ...
Quarter-square representations:
r(0) = 0,
r(1) = 1,
r(2) = 2,
r(3) = 2 + 1,
r(15) = 12 + 2 + 1,
r(6969) = 6889 + 72 + 6 + 2.
MATHEMATICA
z = 200; b[n_] := Floor[(n + 1)^2/4]; bb = Table[b[n], {n, 0, z}];
s[n_] := Table[b[n], {k, b[n + 1] - b[n]}];
h[1] = {1}; h[n_] := Join[h[n - 1], s[n]]; g = h[200]; r[0] = {0};
r[n_] := If[MemberQ[bb, n], {n}, Join[{g[[n]]}, r[n - g[[n]]]]];
u = Table[Length[r[n]], {n, 0, 4 z}] (* A257023 *)
TableForm[Table[Take[Flatten[-1 + Position[u, k]], 10], {k, 1, 4}]] (*A257018 array *)
t = Table[Take[Flatten[-1 + Position[u, k]], 30], {k, 1, 4}];
Flatten[Table[t[[i, j]], {j, 1, 30}, {i, 1, 4}]] (*A257018 sequence *)
CROSSREFS
KEYWORD
nonn,easy,tabf
AUTHOR
Clark Kimberling, Apr 15 2015
STATUS
approved