login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A270439 Alternating sum of nonsquares (A000037). 1
2, -1, 4, -2, 5, -3, 7, -4, 8, -5, 9, -6, 11, -7, 12, -8, 13, -9, 14, -10, 16, -11, 17, -12, 18, -13, 19, -14, 20, -15, 22, -16, 23, -17, 24, -18, 25, -19, 26, -20, 27, -21, 29, -22, 30, -23, 31, -24, 32, -25, 33, -26, 34, -27, 35, -28, 37, -29, 38, -30, 39, -31, 40, -32, 41, -33, 42, -34, 43, -35, 44, -36, 46, -37, 47 (list; graph; refs; listen; history; text; internal format)
OFFSET
1,1
COMMENTS
Interleaving of nontriangular numbers (A014132) and negative integers (A001478).
LINKS
FORMULA
a(n) = Sum_{k = 1..n} (-1)^(k+1)*(k + floor(1/2 + sqrt(k))).
a(n) = Sum_{k = 1..n} (-1)^(k+1)*A000037(k).
a(2^k*m) = -2^(k-1) * m, k > 0.
a(2k - 1) = k + floor(1/2 + sqrt(2*k)), a(2k) = -k, k > 0.
a(2k - 1) = A014132(k), a(2k) = A001478(k).
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
Sequence in context: A054269 A086450 A370153 * A106044 A124896 A008742
KEYWORD
easy,sign
AUTHOR
Ilya Gutkovskiy, Jul 12 2016
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified May 5 10:46 EDT 2024. Contains 372275 sequences. (Running on oeis4.)