OFFSET
1,3
COMMENTS
Record high values of a(n)/n approach sqrt(2) and occur at values of n that are terms of A011900; a(A011900(k)) = A046090(k). - Jon E. Schoenfield, Jun 23 2022
It appears that the sequence 1,2,4,5,6,8,... (the largest integer in the t(n) sum) is A288998. - Michel Marcus, Jun 24 2022
FORMULA
From Jon E. Schoenfield, Jun 23 2022: (Start)
a(n) = t(n) - s(n) where
s(n) = n*(n-1)/2,
j = floor(sqrt(8*n^2 - 8*n + 1)),
m = ceiling(j/2) - n + 1, and
t(n) = (m*(m + 2*n - 1))/2. (End)
EXAMPLE
a(6) = -s(6) + t(6):
s(6) is the sum of the first 6 nonnegative integers = 6*5 / 2 = 15.
t(6) is the smallest sum k of consecutive integers starting from n = 6 such that k > s(6) = 15.
The first few sets of consecutive integers starting from 6 are
{6}, whose elements add up to 6,
{6, 7}, whose elements add up to 13,
{6, 7, 8}, whose elements add up to 21,
{6, 7, 8, 9}, whose elements add up to 30,
...
the smallest sum that is > 15 is 21, so t(6) = 21, so a(6) = -15 + 21 = 6.
PROG
(JavaScript)
function a(n) {
var sum = 0;
for (var i = 0; i < n; i++)
sum -= i;
while (sum <= 0)
sum += i++;
return sum;
}
(PARI) a(n) = my(t=0, s=n*(n-1)/2, k=n); until (t > s, t += k; k ++); t-s; \\ Michel Marcus, Jun 24 2022
(Python)
from math import isqrt
def A355182(n): return ((m:=(isqrt(((k:=n*(n-1))<<3)+1)+1)>>1)*(m+1)>>1)-k # Chai Wah Wu, Jul 14 2022
CROSSREFS
KEYWORD
nonn
AUTHOR
Andrea La Rosa, Jun 23 2022
STATUS
approved