%I #16 Dec 12 2023 18:16:12
%S 0,2,1,4,0,5,11,2,9,17,1,11,22,34,9,22,36,0,15,32,50,1,20,40,61,83,19,
%T 42,66,92,11,38,66,95,125,25,56,88,121,0,34,69,106,144,0,39,79,120,
%U 162,205,36,80,125,171,218,22,70,120,171,223,276,51,105,160,216,273,17,75,134,194,255,317,28,91,156,222,289,357,33,102,172,243,315
%N Sum_{k=0..n} (-1)^issquare(p(k))*p(k) where p=A282840 is the lexicographic-first permutation of the nonnegative integers such that these sums always remain nonnegative.
%C In short: subtract squares when you can, else add nonsquares.
%C A variant of A282846 (corresponding to permutation A282864) and A282865: In those variants, "square" is replaced by "prime".
%C The graph yields a nice moirée pattern.
%H Robert Israel, <a href="/A282886/b282886.txt">Table of n, a(n) for n = 0..10000</a>
%e Starting from a(0)=0 we cannot subtract the square 1, so we add 2 to get a(1)=2, then we can subtract 1, a(2)=1. Now we must add nonsquare 3 to get a(3)=4 before subtracting the square 4, to yield zero sum a(4)=0. Now we have to add nonsquares 5, a(5)=5, and 6, a(6)=11, before subtracting the next square 9, a(7)=2. And so on.
%p a:= 1: b:= 2:
%p S[0]:= 0:
%p for n from 1 to 100 do
%p if S[n-1] - a^2 >= 0 then
%p S[n]:= S[n-1] - a^2; a:= a+1;
%p else S[n]:= S[n-1] + b; b:= b+1;
%p if issqr(b) then b:= b+1 fi
%p fi
%p od:
%p seq(S[i],i=0..100); # _Robert Israel_, Apr 15 2019
%o (PARI) {print1(a=0); c=1; p=2; for(n=1, 199, if(a<c^2, a+=p; while(issquare(p++),), a-=c^2; c++); print1(","a))}
%K nonn,look
%O 0,2
%A _M. F. Hasler_ and _Eric Angelini_, Feb 24 2017