login
A282887
Sum_{k=0..n} -(-1)^issquare(p(k))*p(k), where p = A282887 is the lexicographic-first permutation of the nonnegative integers such that these sums always remain nonnegative.
3
0, 1, 5, 3, 0, 9, 4, 20, 14, 7, 32, 24, 14, 3, 39, 27, 14, 0, 49, 34, 17, 81, 63, 44, 24, 3, 84, 62, 39, 15, 115, 89, 62, 34, 5, 126, 96, 65, 33, 0, 144, 110, 75, 38, 0, 169, 130, 90, 49, 7, 203, 160, 116, 71, 25, 250, 203, 155, 105, 54, 2, 258, 205, 151, 96, 40, 329, 272, 214, 155, 95, 34, 358, 296, 233, 168, 102, 35, 396, 328, 259, 189, 118
OFFSET
0,3
COMMENTS
In short: add squares, and subtract nonsquares when you can.
A variant of A282886 (corresponding to permutation A282840) and A282846 (corresponding to permutation A282864) and A282865; in the latter variants, "square" is replaced by "prime".
The graph yields a nice moirée pattern.
LINKS
EXAMPLE
Starting from a(0)=0 we add the square 1 to get a(1)=1, and since we can't yet subtract 2, we also add the next larger square 4, to get a(2)=5. Then we can subtract nonsquares 2, a(3)=3, and 3, a(4)=0. Now we must add the square 9 to get a(5)=9 before subtracting the nonsquare 5, a(6)=4. Since we can't subtract the nonsquare 6, we add the square 16, a(7)=20. And so on.
PROG
(PARI) {print1(a=0); c=1; p=2; for(n=1, 199, if(a>=p, a-=p; while(issquare(p++), ), a+=c^2; c++); print1(", "a))}
CROSSREFS
Sequence in context: A065469 A249522 A243381 * A265729 A181886 A126853
KEYWORD
nonn
AUTHOR
M. F. Hasler and Eric Angelini, Feb 24 2017
STATUS
approved