login
A282840
Lexicographic-first permutation of the nonnegative integers such that the partial sums (-1)^issquare(a(n))*a(n) always remain nonnegative.
4
0, 2, 1, 3, 4, 5, 6, 9, 7, 8, 16, 10, 11, 12, 25, 13, 14, 36, 15, 17, 18, 49, 19, 20, 21, 22, 64, 23, 24, 26, 81, 27, 28, 29, 30, 100, 31, 32, 33, 121, 34, 35, 37, 38, 144, 39, 40, 41, 42, 43, 169, 44, 45, 46, 47, 196, 48, 50, 51, 52, 53, 225, 54, 55, 56, 57, 256, 58, 59, 60, 61, 62, 289, 63, 65, 66, 67, 68, 324, 69, 70, 71, 72, 73, 361, 74, 75, 76
OFFSET
0,2
COMMENTS
In short: subtract squares when you can, else add nonsquares.
A variant of A282864 (with partial sums A282846) and A282865: In those variants, "square" is replaced by "prime".
The graph is a "superposition" of the nonsquares (on a roughly straight line of slope 1) and the squares in slowly increasingly spaced positions (at indices 0, 2, 4, 7, 10, 14, 17, 21,...: distances 2, 3, 4, 5, 6, 7,... appear 2, 3, 4, 5, 7, 9,... times, respectively).
The graph of the partial (signed) sums yields a nice "moirée" pattern, see A282886.
The variant with opposite signs (subtract nonsquares, add squares) is A282888, with sums A282887.
LINKS
EXAMPLE
Starting from 0 we cannot subtract the square 1, so we add a(1)=2, then we can subtract a(2)=1. Now we must add nonsquare a(3)=3 before subtracting the square a(4)=4 (to yield zero sum). Now we have to add nonsquares a(5)=5 and a(6)=6 before subtracting the next square, a(7)=9. And so on.
MAPLE
a:= 1: b:= 2:
A[0]:= 0: S:= 0:
for n from 1 to 100 do
if S - a^2 >= 0 then
A[n]:= a^2; S:= S - a^2; a:= a+1;
else A[n]:= b; S:= S + b; b:= b+1;
if issqr(b) then b:= b+1 fi
fi
od:
seq(A[i], i=0..100); # Robert Israel, Apr 15 2019
PROG
(PARI) {print1(a=0); c=1; p=2; for(n=1, 199, print1(", "abs(a+0*if(a<c^2, a+=p; while(issquare(p++), ), a-=c^2; c++)-a)))}
CROSSREFS
Sequence in context: A345903 A346786 A239469 * A370655 A082750 A048212
KEYWORD
nonn,look
AUTHOR
M. F. Hasler and Eric Angelini, Feb 24 2017
STATUS
approved