OFFSET
1,3
COMMENTS
A089398(n) = n-th column sum of binary digits of k*2^(k-1), where summation is over all k>=1, without carrying from columns sums that may exceed 2.
FORMULA
a(n) = n/2+1/2*sum(k=1, n, (-1)^floor((n-k)/2^(k-1))). - Benoit Cloitre, Mar 28 2005
Let a(0)=0; when n - 2^[log_2(n)] <= [log_2(n)] then a(n) = a(n - 2^[log_2(n)]) + n - [log_2(n)], else a(n) = a(n - 2^[log_2(n)]) + 2^[log_2(n)] - 1. Thus a(2^m) = 2^m - m for all m>=0; for 0<=k<=m: a(2^m + k) = a(k) + 2^m + k - m; for m<k<=2^m: a(2^m + k) = a(k) + 2^m - 1. - Paul D. Hanna, Mar 28 2005
EXAMPLE
a(6)=5 since 7 - A089398(2^7 + 6) = 7 - 2 = 5.
MATHEMATICA
f[n_] := Block[{lg = Floor[Log[2, n]] + 1}, Sum[ Join[ Reverse[ IntegerDigits[n - i + 1, 2]], {0}][[i]], {i, lg}]]; Table[n - f[2^n + n] + 2, {n, 0, 72}] (* Robert G. Wilson v, Mar 29 2005 *)
PROG
(PARI) a(n)=n/2+1/2*sum(k=1, n, (-1)^floor((n-k)/2^(k-1))) \\ Benoit Cloitre
(PARI) {a(n)=if(n<=0, 0, m=floor(log(n)/log(2)); if(n-2^m<=m, n-m+a(n-2^m), 2^m-1+a(n-2^m)))} \\ Paul D. Hanna, Mar 28 2005
CROSSREFS
KEYWORD
nonn
AUTHOR
Paul D. Hanna, Oct 30 2003
EXTENSIONS
More terms from Benoit Cloitre and Robert G. Wilson v, Mar 28 2005
STATUS
approved