OFFSET
0,8
COMMENTS
a(n) = 0 for n in {0, 1, 3, 8, 20, 34} = A224421.
LINKS
Paolo Xausa, Table of n, a(n) for n = 0..9999
Wikipedia, Triangular number.
EXAMPLE
a(4) = 1 because the sum of the first 4 positive triangular numbers is 1 + 3 + 6 + 10 = 20, the nearest triangular number is 21 and 21 - 20 = 1.
MATHEMATICA
nterms=100; Table[ts=n(n+1)(n+2)/3; t=Floor[Sqrt[ts]]; Abs[t^2+t-ts]/2, {n, 0, nterms-1}]
PROG
(PARI)
a(n)=my(ts=n*(n+1)*(n+2)/3, t=sqrtint(ts)); abs(t^2+t-ts)/2;
vector(100, n, a(n-1)) \\ Paolo Xausa, Jul 06 2022
(Python)
from math import isqrt
def A354330(n): return abs((m:=isqrt(k:=n*(n*(n + 3) + 2)//3))*(m+1)-k)>>1 # Chai Wah Wu, Jul 15 2022
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Paolo Xausa, Jun 04 2022
STATUS
approved