OFFSET
0,2
COMMENTS
LINKS
Robert Israel, Table of n, a(n) for n = 0..10000
EXAMPLE
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.
MAPLE
a:= 1: b:= 2:
S[0]:= 0:
for n from 1 to 100 do
if S[n-1] - a^2 >= 0 then
S[n]:= S[n-1] - a^2; a:= a+1;
else S[n]:= S[n-1] + b; b:= b+1;
if issqr(b) then b:= b+1 fi
fi
od:
seq(S[i], i=0..100); # Robert Israel, Apr 15 2019
PROG
(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))}
CROSSREFS
KEYWORD
nonn,look
AUTHOR
M. F. Hasler and Eric Angelini, Feb 24 2017
STATUS
approved