OFFSET
0,4
COMMENTS
If s(n) is A004718, then a(2n) = n - s(n) and a(2n+1) = n+1.
LINKS
Alois P. Heinz, Table of n, a(n) for n = 0..10000
Yu Hin (Gary) Au, Christopher Drexler-Lemire & Jeffrey Shallit, Notes and note pairs in Nørgård's infinity series, Journal of Mathematics and Music, Volume 11, 2017, Issue 1, pages 1-19.
MAPLE
b:= proc(n) option remember; local r; `if`(n=0, 0,
`if`(irem(n, 2, 'r')=0, -b(r), b(r)+1))
end:
a:= proc(n) a(n):= b(n)+`if`(n=0, 0, a(n-1)) end:
seq(a(n), n=0..100); # Alois P. Heinz, Jun 30 2016
MATHEMATICA
b[n_] := b[n] = Module[{q, r}, If[n == 0, 0, {q, r} = QuotientRemainder[n, 2]; If[r == 0, -b[q], b[q] + 1]]];
a[n_] := b[n] + If[n == 0, 0, a[n - 1]];
a /@ Range[0, 100] (* Jean-François Alcover, Nov 24 2020, after Alois P. Heinz *)
PROG
(Python)
from itertools import groupby
def A274604(n):
if n&1: return (n>>1)+1
c = 0
for k, g in groupby(bin(m:=n>>1)[2:]):
c = c+len(list(g)) if k == '1' else (-c if len(list(g))&1 else c)
return m-c # Chai Wah Wu, Mar 03 2023
CROSSREFS
KEYWORD
nonn
AUTHOR
Jeffrey Shallit, Jun 30 2016
STATUS
approved