login
Numbers having more than 2 or fewer than 2 ones in their binary representation.
3

%I #20 Oct 30 2024 13:31:14

%S 0,1,2,4,7,8,11,13,14,15,16,19,21,22,23,25,26,27,28,29,30,31,32,35,37,

%T 38,39,41,42,43,44,45,46,47,49,50,51,52,53,54,55,56,57,58,59,60,61,62,

%U 63,64,67,69,70,71,73,74,75,76,77,78,79,81,82,83,84,85,86,87,88,89,90

%N Numbers having more than 2 or fewer than 2 ones in their binary representation.

%C A000120(a(n)) <> 2.

%C Complement of A018900; A151774(a(n)) = 0.

%H Reinhard Zumkeller, <a href="/A161989/b161989.txt">Table of n, a(n) for n = 1..10000</a>

%t Select[Range[0,100],DigitCount[#,2,1]!=2&] (* _Harvey P. Dale_, Mar 11 2013 *)

%o (PARI) isok(n) = hammingweight(n) != 2; \\ _Michel Marcus_, Nov 01 2019

%o (Python)

%o from itertools import count, islice

%o from math import comb

%o def A161989(n):

%o def f(x):

%o s = bin(x)[2:]

%o c = n-1+comb((l:=len(s))-1,2)

%o try:

%o c += l-1-s[1:].index('1')

%o except:

%o pass

%o return c

%o m, k = n-1, f(n-1)

%o while m != k: m, k = k, f(k)

%o return m

%o def A161989_gen(): # generator of terms

%o return filter(lambda n:n.bit_count()!=2,count(0))

%o A161989_list = list(islice(A161989_gen(),50)) # _Chai Wah Wu_, Oct 30 2024

%Y Cf. A000120, A018900, A151774.

%K nonn

%O 1,3

%A _Reinhard Zumkeller_, Jun 24 2009