This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A343852 #36 Dec 19 2024 19:47:52 %S A343852 5,10,9,20,21,18,17,40,19,42,38,36,37,34,33,80,35,38,37,84,35,76,74, %T A343852 72,73,74,70,68,69,66,65,160,67,70,69,76,67,74,73,168,75,70,69,152,67, %U A343852 148,146,144,71,146,145,148,140,140,138,136,137,138,134,132,133 %N A343852 a(n) is the least k > 0 such that the binary expansions of k and of n + k have the same numbers of 0's and of 1's. %C A343852 This is the binary analog of A343888. %C A343852 The required comparisons are (1) that the number of ones in the binary expansion of k must equal the number of ones in the binary expansion of k+n, and (2) that the number of zeroes in the binary expansion of k must equal the number of zeroes in the binary expansion of k+n. See the example below. - _Harvey P. Dale_, Dec 19 2024 %H A343852 Rémy Sigrist, <a href="/A343852/b343852.txt">Table of n, a(n) for n = 1..8191</a> %F A343852 a(n) <= A004757(n). %e A343852 The first terms, alongside the binary expansions of a(n) and of n + a(n), are: %e A343852 n a(n) bin(a(n)) bin(n+a(n)) %e A343852 -- ---- --------- ----------- %e A343852 1 5 101 110 %e A343852 2 10 1010 1100 %e A343852 3 9 1001 1100 %e A343852 4 20 10100 11000 %e A343852 5 21 10101 11010 %e A343852 6 18 10010 11000 %e A343852 7 17 10001 11000 %e A343852 8 40 101000 110000 %e A343852 9 19 10011 11100 %e A343852 10 42 101010 110100 %e A343852 11 38 100110 110001 %e A343852 12 36 100100 110000 %e A343852 13 37 100101 110010 %e A343852 14 34 100010 110000 %e A343852 15 33 100001 110000 %t A343852 lk[n_]:=Module[{k=1},While[DigitCount[k,2,0]!=DigitCount[n+k,2,0]||DigitCount[k,2,1]!=DigitCount[n+k,2,1],k++];k]; Array[lk,70] (* _Harvey P. Dale_, Dec 19 2024 *) %o A343852 (PARI) a(n) = { for (k=1, oo, if (#binary(k)==#binary(n+k) && hammingweight(k)==hammingweight(n+k), return (k))) } %o A343852 (Python) %o A343852 def a(n): %o A343852 k = 1 %o A343852 while k.bit_length() != (n+k).bit_length() or bin(k).count('1') != bin(n+k).count('1'): k += 1 %o A343852 return k %o A343852 print([a(n) for n in range(1, 62)]) # _Michael S. Branicky_, May 04 2021 %Y A343852 Cf. A000120, A004757, A023416, A293198, A343888. %K A343852 nonn,base %O A343852 1,1 %A A343852 _Rémy Sigrist_, May 03 2021