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