OFFSET
1,1
FORMULA
Set R = round(sqrt(2*n)), then a(n) = n^2+n+R*((6*n+1)-R^2)/6.
EXAMPLE
a(1) = 3;
a(2) = 3+6 = 9;
a(3) = 3+6+8 = 17;
a(4) = 3+6+8+11 = 28.
PROG
(PARI) vector(80, n, R = round(sqrt(2*n)); n^2+n+R*((6*n+1)-R^2)/6) \\ Michel Marcus, Apr 17 2015
(Python)
from math import isqrt
def A171152(n): return n*(n+1)+(r:=(m:=isqrt(k:=n<<1))+int((k-m*(m+1)<<2)>=1))*(3*k+1-r**2)//6 # Chai Wah Wu, Jul 30 2022
CROSSREFS
KEYWORD
nonn
AUTHOR
Gerald Hillier, Dec 04 2009
EXTENSIONS
More terms from Michel Marcus, Apr 17 2015
STATUS
approved