login
Replace 2^k in binary expansion of n with k-th prime number for any k > 0 (and keep 2^0).
3

%I #24 May 26 2024 18:29:57

%S 0,1,2,3,3,4,5,6,5,6,7,8,8,9,10,11,7,8,9,10,10,11,12,13,12,13,14,15,

%T 15,16,17,18,11,12,13,14,14,15,16,17,16,17,18,19,19,20,21,22,18,19,20,

%U 21,21,22,23,24,23,24,25,26,26,27,28,29,13,14,15,16,16

%N Replace 2^k in binary expansion of n with k-th prime number for any k > 0 (and keep 2^0).

%C Every nonnegative integer appears in this sequence as A008578 is a complete sequence.

%C For any m >= 0, m appears A036497(m) times, the first and last occurrences being at indices A345297(m) and A200947(m), respectively. - _Rémy Sigrist_, Jun 13 2021

%H Rémy Sigrist, <a href="/A331835/b331835.txt">Table of n, a(n) for n = 0..8192</a>

%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/CompleteSequence.html">Complete Sequence</a>

%H <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>

%F a(2*n) = A089625(n) for any n > 0.

%F a(2*n+1) = A089625(n) + 1 for any n > 0.

%F G.f.: x/(1 - x^2) + (1/(1 - x)) * Sum_{k>=1} prime(k) * x^(2^k) / (1 + x^(2^k)). - _Ilya Gutkovskiy_, May 24 2024

%e For n = 43:

%e - 43 = 2^0 + 2^1 + 2^3 + 2^5,

%e - so a(43) = 2^0 + prime(1) + prime(3) + prime(5) = 1 + 2 + 5 + 11 = 19.

%t Array[Total@ Map[If[# == 0, 1, Prime[#]] &, Position[Reverse@ IntegerDigits[#, 2], 1][[All, 1]] - 1] &, 68] (* _Michael De Vlieger_, Jan 29 2020 *)

%o (PARI) a(n) = my (b=Vecrev(binary(n\2))); n%2 + sum(k=1, #b, if (b[k], prime(k), 0))

%o (Python)

%o from sympy import prime

%o def p(n): return prime(n) if n >= 1 else 1

%o def a(n): return sum(p(i)*int(b) for i, b in enumerate(bin(n)[:1:-1]))

%o print([a(n) for n in range(69)]) # _Michael S. Branicky_, Jun 13 2021

%Y Cf. A008578, A036497, A048672, A089625, A200947, A345297.

%K nonn,base

%O 0,3

%A _Rémy Sigrist_, Jan 28 2020