A090706 Number of numbers having in binary representation the same number of zeros and ones as n has.
1, 1, 1, 1, 1, 2, 2, 1, 1, 3, 3, 3, 3, 3, 3, 1, 1, 4, 4, 6, 4, 6, 6, 4, 4, 6, 6, 4, 6, 4, 4, 1, 1, 5, 5, 10, 5, 10, 10, 10, 5, 10, 10, 10, 10, 10, 10, 5, 5, 10, 10, 10, 10, 10, 10, 5, 10, 10, 10, 5, 10, 5, 5, 1, 1, 6, 6, 15, 6, 15, 15, 20, 6, 15, 15, 20, 15, 20, 20, 15, 6, 15, 15, 20, 15, 20
Offset: 0
Examples
From _Ruud H.G. van Tol_, Apr 17 2014: (Start) n=25->'11001': a(25) = #{'10011'->19, '10101'->21, '10110'->22, '11001'->25, '11010'->26, '11100'->28} = 6. n=23->'1_0111' has 5 bits, and the lower 4 bits can be shuffled. There are 1 zero and 3 ones, so the number of combinations is C(4,1) = 4 (the zero can be in 4 positions). n=31->'1_1111': C(4,4) = 1. n=33->'1_00001': C(5,1) = 5 (the one can be in 5 positions). n=35->'1_00011': C(5,2) = 10. (End)
Links
- Reinhard Zumkeller, Table of n, a(n) for n = 0..10000
- Eric Weisstein's World of Mathematics, Binary
- Eric Weisstein's World of Mathematics, Digit Count
- Index entries for sequences related to binary expansion of n
Programs
-
Mathematica
a[n_] := Binomial[Length[b = IntegerDigits[n, 2]]-1, Count[b, 0]]; a[0] = 1; Table[a[n], {n, 0, 100}] (* Jean-François Alcover, Apr 25 2014 *)
-
PARI
A090706 = n->binomial(#binary(n)-1,hammingweight(n)-(n>0)) \\ About 20% faster than the alternative "...-1)+!n". - M. F. Hasler, Jan 04 2014
-
Python
from math import comb def A090706(n): return comb(n.bit_length()-1,n.bit_count()-1) if n else 1 # Chai Wah Wu, Mar 06 2025
Extensions
Missing a(0)=1 added and offset adjusted by Reinhard Zumkeller, Dec 19 2012