login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

a(n) is the sum of all integers whose binary representation is contained in the binary representation of n (with multiplicity).
0

%I #31 Dec 13 2019 12:37:43

%S 0,1,3,5,7,10,13,16,15,19,24,28,29,33,38,42,31,36,43,48,52,57,64,69,

%T 61,66,73,78,82,87,94,99,63,69,78,84,91,97,106,112,108,114,123,129,

%U 136,142,151,157,125,131,140,146,153,159,168,174,170,176,185,191,198

%N a(n) is the sum of all integers whose binary representation is contained in the binary representation of n (with multiplicity).

%F a(2^k) = 2^(k+1)-1.

%F a(2^k-1) = (8*2^k-8-5*k-k^2)/2. - _Giovanni Resta_, Dec 02 2019

%e For n = 5: 5 in binary is 101, so a(n) = 101 + 10 + 01 + 1 + 0 + 1 in binary, which is 5 + 2 + 1 + 1 + 0 + 1 = 10.

%t a[n_] := Block[{d = IntegerDigits[n, 2]}, Sum[FromDigits[Take[d, {i, j}], 2], {j, Length[d]}, {i, j}]]; Array[a, 61, 0] (* _Giovanni Resta_, Dec 02 2019 *)

%o (Python)

%o def bitlist(n):

%o output = []

%o while n != 0:

%o output.append(n % 2)

%o n /= 2

%o return output

%o #converts a number into a list of the digits in binary reversed

%o def bitsum(bitlist):

%o output = 0

%o for bit in bitlist:

%o if bit == 1:

%o output += 1

%o return output

%o #gives the cross sum of a bitlist

%o def a(bitlist):

%o output = 0

%o l = len(bitlist)

%o for x in range(l):

%o output += bitlist[x] * (l - x) * (2**(x + 1) - 1)

%o return output

%o #to get the first n numbers of the sequence, write:

%o for x in range(1, n + 1):

%o print x, a(bitlist(x))

%Y Cf. A007088, A078823, A225580.

%K nonn,base

%O 0,3

%A _Tonio Kettner_, Nov 30 2019