A227361 If n is even, then a(n) = n + bitsum(n), else a(n) = n - bitsum(n), where bitsum(n) is the count of binary 1's in n, A000120.
0, 0, 3, 1, 5, 3, 8, 4, 9, 7, 12, 8, 14, 10, 17, 11, 17, 15, 20, 16, 22, 18, 25, 19, 26, 22, 29, 23, 31, 25, 34, 26, 33, 31, 36, 32, 38, 34, 41, 35, 42, 38, 45, 39, 47, 41, 50, 42, 50, 46, 53, 47, 55, 49, 58, 50, 59, 53, 62, 54, 64, 56, 67, 57, 65, 63, 68, 64, 70, 66, 73, 67, 74, 70, 77, 71, 79, 73, 82, 74, 82, 78, 85, 79, 87, 81, 90, 82, 91, 85
Offset: 0
Examples
a(0) = 0 because 0 is even, so 0 + bitsum(0) = 0. a(1) = 0 because 1 is odd, so 1 - bitsum(1) = 0. a(2) = 3 because 2 is even, so 2 + bitsum(2) = 3. a(3) = 1 because 3 is odd, so 3 - bitsum(3) = 1.
Links
- Andres M. Torres, Table of n, a(n) for n = 0..10000
Programs
-
Blitz3D
;; Each a(n) is generated simply as follows: a(n) = BitStoneA(n) Function BitStoneA(n) If (n Mod 2) ;; if is odd Return n-bitsum(n) Else ;; if is even Return n+bitsum(n) End If End Function ;; --- Or, If n is even, then return n+A000120(n), else return n-A000120(n), where A000120(n) = bitsum(n)
-
Mathematica
Table[n + (-1)^n DigitCount[n, 2, 1], {n, 0, 127}] (* Alonso del Arte, Jul 08 2013 *)
-
PARI
a(n)=n+(-1)^(n%2)*hammingweight(n) \\ Charles R Greathouse IV, Jul 09 2013
Formula
a(n) = n + (-1)^n * Sum_{j = 1 .. floor(log_2(n)) + 1} (floor(n/2^j + 1/2) - floor(n/2^j)). - Alonso del Arte, Jul 08 2013, based on one of Hieronymus Fischer's formulas for A000120.
Comments