OFFSET
1,1
FORMULA
EXAMPLE
a(1) = a(2*1-1) = 1 + floor(1/2 + sqrt(2*1)) = 2;
a(2) = a(2*1) = -1;
a(3) = a(2*2-1) = 2 + floor(1/2 + sqrt(2*2)) = 4;
a(4) = a(2*2) = -2;
a(5) = a(2*3-1) = 3 + floor(1/2 + sqrt(2*3)) = 5;
a(6) = a(2*3) = -3, etc.
or
a(1) = 2;
a(2) = 2 - 3 = -1;
a(3) = 2 - 3 + 5 = 4;
a(4) = 2 - 3 + 5 - 6 = -2;
a(5) = 2 - 3 + 5 - 6 + 7 = 5;
a(6) = 2 - 3 + 5 - 6 + 7 - 8 = -3, etc.
(2, 3, 5, 6, 7, 8, ... is the nonsquares).
MATHEMATICA
Table[Sum[(-1)^(k + 1) (k + Floor[1/2 + Sqrt[k]]), {k, n}], {n, 75}]
PROG
(PARI) a(n)=if(n%2, sqrtint(4*n-3)+n+2, -n)\2 \\ Charles R Greathouse IV, Aug 03 2016
(Python)
from math import isqrt
def A270439(n): return (n>>1)+1+(m:=isqrt(n+1))+int(n-m*(m+1)>=0) if n&1 else -(n>>1) # Chai Wah Wu, Nov 14 2022
CROSSREFS
KEYWORD
easy,sign
AUTHOR
Ilya Gutkovskiy, Jul 12 2016
STATUS
approved