cp's OEIS Frontend

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.

Showing 1-10 of 25 results. Next

A031443 Digitally balanced numbers: positive numbers that in base 2 have the same number of 0's as 1's.

Original entry on oeis.org

2, 9, 10, 12, 35, 37, 38, 41, 42, 44, 49, 50, 52, 56, 135, 139, 141, 142, 147, 149, 150, 153, 154, 156, 163, 165, 166, 169, 170, 172, 177, 178, 180, 184, 195, 197, 198, 201, 202, 204, 209, 210, 212, 216, 225, 226, 228, 232, 240, 527, 535, 539, 541, 542, 551
Offset: 1

Views

Author

Keywords

Comments

Also numbers k such that the binary digital mean dm(2, k) = (Sum_{i=1..d} 2*d_i - 1) / (2*d) = 0, where d is the number of digits in the binary representation of k and d_i the individual digits. - Reikku Kulon, Sep 21 2008
From Reikku Kulon, Sep 29 2008: (Start)
Each run of values begins with 2^(2k + 1) + 2^(k + 1) - 2^k - 1. The initial values increase according to the sequence {2^(k - 1), 2^(k - 2), 2^(k - 3), ..., 2^(k - k)}.
After this, the values follow a periodic sequence of increases by successive powers of two with single odd values interspersed.
Each run ends with an odd increase followed by increases of {2^(k - k), ..., 2^(k - 2), 2^(k - 1), 2^k}, finally reaching 2^(2k + 2) - 2^(k + 1).
Similar behavior occurs in other bases. (End)
Numbers k such that A000120(k)/A070939(k) = 1/2. - Ctibor O. Zizka, Oct 15 2008
Subsequence of A053754; A179888 is a subsequence. - Reinhard Zumkeller, Jul 31 2010
A000120(a(n)) = A023416(a(n)); A037861(a(n)) = 0.
A001700 gives number of terms having length 2*n in binary representation: A001700(n-1) = #{m: A070939(a(m))=2*n}. - Reinhard Zumkeller, Jun 08 2011
The number of terms below 2^k is A079309(floor(k/2)) for k > 1. - Amiram Eldar, Nov 21 2020

Examples

			9 is a term because '1001' contains 2 '0's and 2 '1's.
		

Crossrefs

Subsequence of A053754.
Row n = 2 of A378000.
Terms of binary width n are enumerated by A001700.

Programs

  • Haskell
    -- See link, showing that Ulrich Schimkes formula provides a very efficient algorithm. Reinhard Zumkeller, Jun 15 2011
    
  • Magma
    [ n: n in [2..250] | Multiplicity({* z: z in Intseq(n,2) *}, 0) eq &+Intseq(n,2) ];  // Bruno Berselli, Jun 07 2011
    
  • Maple
    a:=proc(n) local nn, n1, n0: nn:=convert(n,base,2): n1:=add(nn[i],i=1..nops(nn)): n0:=nops(nn)-n1: if n0=n1 then n else end if end proc: seq(a(n), n = 1..240); # Emeric Deutsch, Jul 31 2008
  • Mathematica
    Select[Range[250],DigitCount[#,2,1]==DigitCount[#,2,0]&] (* Harvey P. Dale, Jul 22 2013 *)
    FromDigits[#,2]&/@DeleteCases[Flatten[Permutations/@Table[PadRight[{},2n,{1,0}],{n,5}],1],?(#[[1]]==0&)]//Sort (* _Harvey P. Dale, May 30 2016 *)
  • PARI
    for(n=1,100,b=binary(n); l=length(b); if(sum(i=1,l, component(b,i))==l/2,print1(n,",")))
    
  • PARI
    is(n)=hammingweight(n)==hammingweight(bitneg(n,#binary(n))) \\ Charles R Greathouse IV, Mar 29 2013
    
  • PARI
    is(n)=2*hammingweight(n)==exponent(n)+1 \\ Charles R Greathouse IV, Apr 18 2020
    
  • Perl
    for my $half ( 1 .. 4 ) {
      my $N = 2 * $half;  # only even widths apply
      my $vector = (1 << ($N-1)) | ((1 << ($N/2-1)) - 1);  # first key
      my $n = 1; $n *= $_ for 2 .. $N;    # N!
      my $d = 1; $d *= $_ for 2 .. $N/2;  # (N/2)!
      for (1 .. $n/($d*$d*2)) {
        print "$vector, ";
        my ($v, $d) = ($vector, 0);
        until ($v & 1 or !$v) { $d = ($d << 1)|1; $v >>= 1 }
        $vector += $d + 1 + (($v ^ ($v + 1)) >> 2);  # next key
      }
    } # Ruud H.G. van Tol, Mar 30 2014
    
  • Python
    from sympy.utilities.iterables import multiset_permutations
    A031443_list = [int('1'+''.join(p),2) for n in range(1,10) for p in multiset_permutations('0'*n+'1'*(n-1))] # Chai Wah Wu, Nov 15 2019

Formula

a(n+1) = a(n) + 2^k + 2^(m-1) - 1 + floor((2^(k+m) - 2^k)/a(n))*(2^(2*m) + 2^(m-1)) where k is the largest integer such that 2^k divides a(n) and m is the largest integer such that 2^m divides a(n)/2^k+1. - Ulrich Schimke (UlrSchimke(AT)aol.com)
A145037(a(n)) = 0. - Reikku Kulon, Oct 02 2008

A037861 (Number of 0's) - (number of 1's) in the base-2 representation of n.

Original entry on oeis.org

1, -1, 0, -2, 1, -1, -1, -3, 2, 0, 0, -2, 0, -2, -2, -4, 3, 1, 1, -1, 1, -1, -1, -3, 1, -1, -1, -3, -1, -3, -3, -5, 4, 2, 2, 0, 2, 0, 0, -2, 2, 0, 0, -2, 0, -2, -2, -4, 2, 0, 0, -2, 0, -2, -2, -4, 0, -2, -2, -4, -2, -4, -4, -6, 5, 3, 3, 1, 3, 1, 1, -1, 3
Offset: 0

Views

Author

Keywords

Comments

-Sum_{n>=1} a(n)/((2*n)*(2*n+1)) = the "alternating Euler constant" log(4/Pi) = 0.24156... - (see A094640 and Sondow 2005, 2010).
a(A072600(n)) < 0; a(A072601(n)) <= 0; a(A031443(n)) = 0; a(A072602(n)) >= 0; a(A072603(n)) > 0; a(A031444(n)) = 1; a(A031448(n)) = -1; abs(a(A089648(n))) <= 1. - Reinhard Zumkeller, Feb 07 2015

Crossrefs

Cf. A031443 for n when a(n)=0, A053738 for n when a(n) odd, A053754 for n when a(n) even, A030300 for a(n+1) mod 2.
See A268289 for a recurrence based on this sequence.

Programs

  • Haskell
    a037861 n = a023416 n - a000120 n  -- Reinhard Zumkeller, Aug 01 2013
    
  • Maple
    A037861:= proc(n) local L;
         L:= convert(n,base,2);
         numboccur(0,L) - numboccur(1,L)
    end proc:
    map(A037861, [$0..100]); # Robert Israel, Mar 08 2016
  • Mathematica
    Table[Count[ IntegerDigits[n, 2], 0] - Count[IntegerDigits[n, 2], 1], {n, 0, 75}]
  • PARI
    a(n) = if (n==0, 1, 1 + logint(n, 2) - 2*hammingweight(n)); \\ Michel Marcus, May 15 2020 and Jun 16 2020
  • Python
    def A037861(n):
        return 2*format(n,'b').count('0')-len(format(n,'b')) # Chai Wah Wu, Mar 07 2016
    

Formula

From Henry Bottomley, Oct 27 2000: (Start)
a(n) = A023416(n) - A000120(n) = A029837(n) - 2*A000120(n) = 2*A023416(n) - A029837(n).
a(2*n) = a(n) + 1; a(2*n + 1) = a(2*n) - 2 = a(n) - 1. (End)
G.f. satisfies A(x) = (1 + x)*A(x^2) - x*(2 + x)/(1 + x). - Franklin T. Adams-Watters, Dec 26 2006
a(n) = b(n) for n > 0 with b(0) = 0 and b(n) = b(floor(n/2)) + (-1)^(n mod 2). - Reinhard Zumkeller, Dec 31 2007
G.f.: 1 + (1/(1 - x))*Sum_{k>=0} x^(2^k)*(x^(2^k) - 1)/(1 + x^(2^k)). - Ilya Gutkovskiy, Apr 07 2018

A372433 Binary weight (number of ones in binary expansion) of the n-th squarefree number.

Original entry on oeis.org

1, 1, 2, 2, 2, 3, 2, 3, 3, 3, 4, 2, 3, 3, 3, 4, 3, 4, 4, 5, 2, 2, 3, 3, 3, 4, 3, 3, 4, 4, 5, 4, 4, 5, 4, 4, 5, 5, 5, 2, 2, 3, 3, 3, 4, 3, 3, 4, 4, 5, 3, 4, 4, 4, 5, 4, 5, 5, 5, 6, 3, 4, 4, 5, 4, 4, 5, 5, 5, 6, 4, 4, 5, 5, 6, 5, 6, 7, 2, 2, 3, 3, 3, 3, 3, 4, 4
Offset: 1

Views

Author

Gus Wiseman, May 04 2024

Keywords

Crossrefs

Restriction of A000120 to A005117.
For prime instead of squarefree we have A014499, zeros A035103.
Counting zeros instead of ones gives A372472, cf. A023416, A372473.
For binary length instead of weight we have A372475.
A003714 lists numbers with no successive binary indices.
A030190 gives binary expansion, reversed A030308.
A048793 lists positions of ones in reversed binary expansion, sum A029931.
A145037 counts ones minus zeros in binary expansion, cf. A031443, A031444, A031448, A097110.
A371571 lists positions of zeros in binary expansion, sum A359359.
A371572 lists positions of ones in binary expansion, sum A230877.
A372515 lists positions of zeros in reversed binary expansion, sum A359400.
A372516 counts ones minus zeros in binary expansion of primes, cf. A177718, A177796, A372538, A372539.

Programs

  • Mathematica
    DigitCount[Select[Range[100],SquareFreeQ],2,1]
    Total[IntegerDigits[#,2]]&/@Select[Range[200],SquareFreeQ] (* Harvey P. Dale, Feb 14 2025 *)
  • Python
    from math import isqrt
    from sympy import mobius
    def A372433(n):
        def f(x): return n+x-sum(mobius(k)*(x//k**2) for k in range(1, isqrt(x)+1))
        m, k = n, f(n)
        while m != k:
            m, k = k, f(k)
        return int(m).bit_count() # Chai Wah Wu, Aug 02 2024

Formula

a(n) = A000120(A005117(n)).
a(n) + A372472(n) = A372475(n) = A070939(A005117(n)).

A039004 Numbers whose base-4 representation has the same number of 1's and 2's.

Original entry on oeis.org

0, 3, 6, 9, 12, 15, 18, 24, 27, 30, 33, 36, 39, 45, 48, 51, 54, 57, 60, 63, 66, 72, 75, 78, 90, 96, 99, 102, 105, 108, 111, 114, 120, 123, 126, 129, 132, 135, 141, 144, 147, 150, 153, 156, 159, 165, 177, 180, 183, 189, 192, 195, 198, 201, 204, 207, 210, 216, 219
Offset: 1

Views

Author

Keywords

Comments

Numbers such that sum (-1)^k*b(k) = 0 where b(k)=k-th binary digit of n (see A065359). - Benoit Cloitre, Nov 18 2003
Conjecture: a(C(2n,n)-1) = 4^n - 1. (A000984 is C(2n,n)). - Gerald McGarvey, Nov 18 2007
From Russell Jay Hendel, Jun 23 2015: (Start)
We prove the McGarvey conjecture (A) a(e(n,n)-1) = 4^n-1, with e(n,m) = A034870(n,m) = binomial(2n,m), the even rows of Pascal's triangle. By the comment from Hendel in A034870, we have the function s(n,k) = #{n-digit, base-4 numbers with n-k more 1-digits than 2-digits}. As shown in A034870, (B) #s(n,k)= e(n,k) with # indicating cardinality, that is, e(n,k) = binomial(2n,k) gives the number of n-digit, base-4 numbers with n-k more 1-digits than 2-digits.
We now show that (B) implies (A). By definition, s(n,n) contains the e(n,n) = binomial(2n,n) numbers with an equal number of 1-digits and 2-digits. The biggest n-digit, base-4 number is 333...3 (n copies of 3). Since 333...33 has zero 1-digits and zero 2-digits it follows that 333...333 is a member of s(n,n) and hence it is the biggest member of s(n,n). But 333...333 (n copies of 3) in base 4 has value 4^n-1. Since A039004 starts with index 0 (that is, 0 is the 0th member of A039004), it immediately follows that 4^n-1 is the (e(n,n)-1)st member of A039004, proving the McGarvey conjecture. (End)
Also numbers whose alternating sum of binary expansion is 0, i.e., positions of zeros in A345927. These are numbers whose binary expansion has the same number of 1's at even positions as at odd positions. - Gus Wiseman, Jul 28 2021

Crossrefs

A subset of A001969 (evil numbers).
A base-2 version is A031443 (digitally balanced numbers).
Positions of 0's in A065359 and A345927.
Positions of first appearances are A086893.
The version for standard compositions is A344619.
A000120 and A080791 count binary digits, with difference A145037.
A003714 lists numbers with no successive binary indices.
A011782 counts compositions.
A030190 gives the binary expansion of each nonnegative integer.
A070939 gives the length of an integer's binary expansion.
A097805 counts compositions by alternating (or reverse-alternating) sum.
A101211 lists run-lengths in binary expansion:
- row-lengths: A069010
- reverse: A227736
- ones only: A245563
A138364 counts compositions with alternating sum 0:
- bisection: A001700/A088218
- complement: A058622
A328594 lists numbers whose binary expansion is aperiodic.
A345197 counts compositions by length and alternating sum.

Programs

  • Fortran
    c See link in A139351.
  • Maple
    N:= 1000: # to get all terms up to N, which should be divisible by 4
    B:= Array(0..N-1):
    d:= ceil(log[4](N));
    S:= Array(0..N-1,[seq(op([0,1,-1,0]),i=1..N/4)]):
    for i from 1 to d do
      B:= B + S;
      S:= Array(0..N-1,i-> S[floor(i/4)]);
    od:
    select(t -> B[t]=0, [$0..N-1]); # Robert Israel, Jun 24 2015
  • Mathematica
    ats[y_]:=Sum[(-1)^(i-1)*y[[i]],{i,Length[y]}];
    Select[Range[0,100],ats[IntegerDigits[#,2]]==0&] (* Gus Wiseman, Jul 28 2021 *)
  • PARI
    for(n=0,219,if(sum(i=1,length(binary(n)),(-1)^i*component(binary(n),i))==0,print1(n,",")))
    

Formula

Conjecture: there is a constant c around 5 such that a(n) is asymptotic to c*n. - Benoit Cloitre, Nov 24 2002
That conjecture is false. The number of members of the sequence from 0 to 4^d-1 is binomial(2d,d) which by Stirling's formula is asymptotic to 4^d/sqrt(Pi*d). If Cloitre's conjecture were true we would have 4^d-1 asymptotic to c*4^d/sqrt(Pi*d), a contradiction. - Robert Israel, Jun 24 2015

A346697 Sum of the odd-indexed parts (odd bisection) of the multiset of prime indices of n.

Original entry on oeis.org

0, 1, 2, 1, 3, 1, 4, 2, 2, 1, 5, 3, 6, 1, 2, 2, 7, 3, 8, 4, 2, 1, 9, 2, 3, 1, 4, 5, 10, 4, 11, 3, 2, 1, 3, 3, 12, 1, 2, 2, 13, 5, 14, 6, 5, 1, 15, 4, 4, 4, 2, 7, 16, 3, 3, 2, 2, 1, 17, 3, 18, 1, 6, 3, 3, 6, 19, 8, 2, 5, 20, 4, 21, 1, 5, 9, 4, 7, 22, 5, 4, 1
Offset: 1

Views

Author

Gus Wiseman, Aug 01 2021

Keywords

Comments

A prime index of n is a number m such that prime(m) divides n. The multiset of prime indices of n is row n of A112798.

Examples

			The prime indices of 1100 are {1,1,3,3,5}, so a(1100) = 1 + 3 + 5 = 9.
The prime indices of 2100 are {1,1,2,3,3,4}, so a(2100) = 1 + 2 + 3 = 6.
		

Crossrefs

The version for standard compositions is A209281(n+1) (even: A346633).
Subtracting the even version gives A316524 (reverse: A344616).
The even version is A346698.
The reverse version is A346699.
The even reverse version is A346700.
A000120 and A080791 count binary digits 1 and 0, with difference A145037.
A000302 counts compositions with odd alternating sum, ranked by A053738.
A001414 adds up prime factors, row sums of A027746.
A029837 adds up parts of standard compositions (alternating: A124754).
A056239 adds up prime indices, row sums of A112798.
A103919 counts partitions by sum and alternating sum (reverse: A344612).
A325534 counts separable partitions, ranked by A335433.
A325535 counts inseparable partitions, ranked by A335448.
A344606 counts alternating permutations of prime indices.

Programs

  • Mathematica
    primeMS[n_]:=If[n==1,{},Flatten[Cases[FactorInteger[n],{p_,k_}:>Table[PrimePi[p],{k}]]]];
    Table[Total[First/@Partition[Append[primeMS[n],0],2]],{n,100}]

Formula

a(n) = A056239(n) - A346698(n).
a(n) = A316524(n) + A346698(n).
a(n odd omega) = A346699(n).
a(n even omega) = A346700(n).
A344616(n) = A346699(n) - A346700(n).

A346698 Sum of the even-indexed parts (even bisection) of the multiset of prime indices of n.

Original entry on oeis.org

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

Views

Author

Gus Wiseman, Aug 01 2021

Keywords

Comments

A prime index of n is a number m such that prime(m) divides n. The multiset of prime indices of n is row n of A112798.

Examples

			The prime indices of 1100 are {1,1,3,3,5}, so a(1100) = 1 + 3 = 4.
The prime indices of 2100 are {1,1,2,3,3,4}, so a(2100) = 1 + 3 + 4 = 8.
		

Crossrefs

Subtracting from the odd version gives A316524 (reverse: A344616).
The version for standard compositions is A346633 (odd: A209281(n+1)).
The odd version is A346697.
The even reverse version is A346699.
The reverse version is A346700.
A000120 and A080791 count binary digits 1 and 0, with difference A145037.
A001414 adds up prime factors, row-sums of A027746.
A029837 adds up parts of standard compositions (alternating: A124754).
A056239 adds up prime indices, row-sums of A112798.
A103919 counts partitions by sum and alternating sum (reverse: A344612).
A325534 counts separable partitions, ranked by A335433.
A325535 counts inseparable partitions, ranked by A335448.
A344606 counts alternating permutations of prime indices.

Programs

  • Mathematica
    primeMS[n_]:=If[n==1,{},Flatten[Cases[FactorInteger[n],{p_,k_}:>Table[PrimePi[p],{k}]]]];
    Table[Total[Last/@Partition[Append[primeMS[n],0],2]],{n,100}]
  • PARI
    A346698(n) = if(1==n,0,my(f=factor(n),s=0,p=0); for(k=1,#f~,while(f[k,2], s += (p%2)*primepi(f[k,1]); f[k,2]--; p++)); (s)); \\ Antti Karttunen, Nov 30 2021

Formula

a(n) = A056239(n) - A346697(n).
a(n) = A346697(n) - A316524(n).
a(n even omega) = A346699(n).
a(n odd omega) = A346700(n).
A344616(n) = A346699(n) - A346700(n).

Extensions

Data section extended up to 105 terms by Antti Karttunen, Nov 30 2021

A372475 Length of binary expansion (or number of bits) of the n-th squarefree number.

Original entry on oeis.org

1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8
Offset: 1

Views

Author

Gus Wiseman, May 09 2024

Keywords

Examples

			The 10th squarefree number is 14, with binary expansion (1,1,1,0), so a(10) = 4.
		

Crossrefs

For prime instead of squarefree we have A035100, 1's A014499, 0's A035103.
Restriction of A070939 to A005117.
Run-lengths are A077643.
For weight instead of length we have A372433 (restrict A000120 to A005117).
For zeros instead of length we have A372472, firsts A372473.
Positions of first appearances are A372540.
A030190 gives binary expansion, reversed A030308.
A048793 lists positions of ones in reversed binary expansion, sum A029931.
A371571 lists positions of zeros in binary expansion, sum A359359.
A371572 lists positions of ones in binary expansion, sum A230877.
A372515 lists positions of zeros in reversed binary expansion, sum A359400.

Programs

  • Mathematica
    IntegerLength[Select[Range[1000],SquareFreeQ],2]
  • Python
    from math import isqrt
    from sympy import mobius
    def A372475(n):
        def f(x): return n+x-sum(mobius(k)*(x//k**2) for k in range(1, isqrt(x)+1))
        m, k = n, f(n)
        while m != k:
            m, k = k, f(k)
        return int(m).bit_length() # Chai Wah Wu, Aug 02 2024

Formula

a(n) = A070939(A005117(n)).
a(n) = A372472(n) + A372433(n).

A372473 Least k such that the k-th squarefree number has exactly n zeros in its binary expansion.

Original entry on oeis.org

1, 2, 7, 12, 21, 40, 79, 158, 315, 1247, 1246, 2492, 4983, 9963, 19921, 39845, 79689, 159361, 318726, 637462, 1274919, 2549835, 5099651, 10199302, 20398665, 40797328, 81594627, 163189198, 326378285, 652756723, 1305513584, 2611027095, 5222054082, 10444108052
Offset: 0

Views

Author

Gus Wiseman, May 09 2024

Keywords

Comments

Note that the data is not strictly increasing.

Examples

			The squarefree numbers A005117(a(n)) together with their binary expansions and binary indices begin:
     1:              1 ~ {1}
     2:             10 ~ {2}
    10:           1010 ~ {2,4}
    17:          10001 ~ {1,5}
    33:         100001 ~ {1,6}
    65:        1000001 ~ {1,7}
   129:       10000001 ~ {1,8}
   257:      100000001 ~ {1,9}
   514:     1000000010 ~ {2,10}
  2051:   100000000011 ~ {1,2,12}
  2049:   100000000001 ~ {1,12}
  4097:  1000000000001 ~ {1,13}
  8193: 10000000000001 ~ {1,14}
		

Crossrefs

Positions of first appearances in A372472.
For prime instead of squarefree we have A372474, A035103, A372517, A014499.
Counting bits (length) gives A372540, firsts of A372475, runs A077643.
Counting 1's (weight) instead of 0's gives A372541, firsts of A372433.
A000120 counts ones in binary expansion (binary weight), zeros A080791.
A005117 lists squarefree numbers.
A030190 gives binary expansion, reversed A030308.
A048793 lists positions of ones in reversed binary expansion, sum A029931.
A070939 gives length of binary expansion (number of bits).
A371571 lists positions of zeros in binary expansion, sum A359359.
A371572 lists positions of ones in binary expansion, sum A230877.
A372515 lists positions of zeros in reversed binary expansion, sum A359400.

Programs

  • Mathematica
    nn=10000;
    spnm[y_]:=Max@@NestWhile[Most,y,Union[#]!=Range[0,Max@@#]&];
    dcs=DigitCount[Select[Range[nn],SquareFreeQ],2,0];
    Table[Position[dcs,i][[1,1]],{i,0,spnm[dcs]}]
  • Python
    from math import isqrt
    from itertools import count
    from sympy import factorint, mobius
    from sympy.utilities.iterables import multiset_permutations
    def A372473(n):
        if n==0: return 1
        for l in count(n):
            m = 1<Chai Wah Wu, May 10 2024

Extensions

a(23)-a(33) from Chai Wah Wu, May 10 2024

A372474 Least k such that the k-th prime number has exactly n zeros in its binary expansion.

Original entry on oeis.org

2, 1, 8, 7, 19, 32, 99, 55, 174, 310, 565, 1029, 1902, 3513, 6544, 6543, 23001, 43395, 82029, 155612, 295957, 564164, 1077901, 3957811, 3965052, 7605342, 14630844, 28194383, 54400029, 105097568, 393615809, 393615807, 762939128, 1480206930, 2874398838, 5586502349
Offset: 0

Views

Author

Gus Wiseman, May 11 2024

Keywords

Examples

			The prime numbers A000040(a(n)) together with their binary expansions and binary indices begin:
         3:                          11 ~ {1,2}
         2:                          10 ~ {2}
        19:                       10011 ~ {1,2,5}
        17:                       10001 ~ {1,5}
        67:                     1000011 ~ {1,2,7}
       131:                    10000011 ~ {1,2,8}
       523:                  1000001011 ~ {1,2,4,10}
       257:                   100000001 ~ {1,9}
      1033:                 10000001001 ~ {1,4,11}
      2053:                100000000101 ~ {1,3,12}
      4099:               1000000000011 ~ {1,2,13}
      8209:              10000000010001 ~ {1,5,14}
     16417:             100000000100001 ~ {1,6,15}
     32771:            1000000000000011 ~ {1,2,16}
     65539:           10000000000000011 ~ {1,2,17}
     65537:           10000000000000001 ~ {1,17}
    262147:         1000000000000000011 ~ {1,2,19}
    524353:        10000000000001000001 ~ {1,7,20}
   1048609:       100000000000000100001 ~ {1,6,21}
   2097169:      1000000000000000010001 ~ {1,5,22}
   4194433:     10000000000000010000001 ~ {1,8,23}
   8388617:    100000000000000000001001 ~ {1,4,24}
  16777729:   1000000000000001000000001 ~ {1,10,25}
  67108913: 100000000000000000000110001 ~ {1,5,6,27}
  67239937: 100000000100000000000000001 ~ {1,18,27}
		

Crossrefs

Positions of first appearances in A035103.
For squarefree instead of prime we have A372473, firsts of A372472.
Counting ones (weight) gives A372517, firsts of A014499.
Counting squarefree bits gives A372540, firsts of A372475, runs A077643.
Counting squarefree ones gives A372541, firsts of A372433.
Counting bits (length) gives A372684, firsts of A035100.
A000120 counts ones in binary expansion (binary weight), zeros A080791.
A030190 gives binary expansion, reversed A030308.
A048793 lists positions of ones in reversed binary expansion, sum A029931.
A070939 gives length of binary expansion (number of bits).

Programs

  • Mathematica
    nn=10000;
    spnm[y_]:=Max@@NestWhile[Most,y,Union[#]!=Range[0,Max@@#]&];
    dcs=DigitCount[Select[Range[nn],PrimeQ],2,0];
    Table[Position[dcs,i][[1,1]],{i,0,spnm[dcs]}]
  • Python
    from itertools import count
    from sympy import isprime, primepi
    from sympy.utilities.iterables import multiset_permutations
    def A372474(n):
        for l in count(n):
            m = 1<Chai Wah Wu, May 13 2024

Formula

a(n) = A000720(A066195(n)). - Robert Israel, May 13 2024

Extensions

a(22)-a(35) from and offset corrected by Chai Wah Wu, May 13 2024

A268289 a(0)=0; thereafter a(n) = a(n-1) - A037861(n).

Original entry on oeis.org

0, 1, 1, 3, 2, 3, 4, 7, 5, 5, 5, 7, 7, 9, 11, 15, 12, 11, 10, 11, 10, 11, 12, 15, 14, 15, 16, 19, 20, 23, 26, 31, 27, 25, 23, 23, 21, 21, 21, 23, 21, 21, 21, 23, 23, 25, 27, 31, 29, 29, 29, 31, 31, 33, 35, 39, 39, 41, 43, 47, 49
Offset: 0

Views

Author

Mark Moore, Jan 30 2016

Keywords

Comments

The graph of this sequence is related to the Takagi (blancmange) curve: see Lagarias (2012), Section 9, especially Theorem 9.1. [Corrected by Laura Monroe, Oct 21 2020]
Theorem: a(n) is the cardinality of the set { 1<= m <= n, ((n-m) mod 2^floor(log_2(m)+1)) < 2^floor(log_2(m)) }. See links.
From Laura Monroe, Jun 11 2020: (Start)
Consider a full balanced binary tree with n unlabeled leaves such that for each internal node, the number of leaf descendants of the two children differs by at most 1. Call a tree with this even distribution of leaves "pairwise".
Apply labels to the internal nodes, where an internal node is labeled S if its two children have the same number of leaf descendants, and D if its two children have a different number of leaf descendants, and call this an SD-tree. (For a pairwise tree, this is equivalent to saying that a node is an S-node iff it has an even number of leaf descendants.)
a(n) is then the number of S-nodes on a pairwise SD-tree with n+1 leaves.
This is proved in Props. 17 and 18 of the Monroe et al. article in the links.
One example of such a tree is the summation tree generated by a pairwise summation on n+1 summands (see example below). Another example is the tree representing a neutral single-elimination tournament on n+1 teams, as in A096351.
(End)
From Laura Monroe, Oct 23 2020: (Start)
Subtracting a(n) from n gives a sequence of dilations of increasing length on the dyadic rational points of the Takagi function. The number of points in each dilation is 2^k and the scale of each dilation in both the x and y directions is 2^k, where k = floor(log_2(n+1)).
2^(a(n)) is the number of tree automorphisms on the pairwise (i.e., divide-and-conquer) tree with n+1 leaves.
(End)

Examples

			From _Laura Monroe_, Jun 11 2020: (Start)
For n=2, the pairwise summation on 2+1=3 summands takes the form ((a+b)+c). The corresponding summation tree and SD-tree look like:
       +            D
      / \          / \
     +   c        S   c
    / \          / \
   a   b        a   b
and exactly 1 internal node has an even number of leaf descendants, hence is an S-node.
For n=3, the pairwise summation on 3+1=4 summands takes the form ((a+b)+(c+d)). The corresponding summation tree and SD-tree look like:
       +            S
      / \          / \
     +   +        S   S
    /|   |\      /|   |\
   a b   c d    a b   c d
and exactly 3 internal nodes have an even number of leaf descendants, hence are S-nodes.
(End)
		

Crossrefs

Programs

  • C
    int a(int n)   {
        int m=n+1;
        int result=0;
        int i=0;
        while (n) {
            int ith_bit_set = m&(1<>= 1;
        }
       return result;
    }
    /* Laura Monroe, Jun 17 2020 */
    
  • Julia
    function A268289List(len)
        A = zeros(Int, len)
        for n in 1:len-1
            a, b, c = n, n & 1, 1
            while (a >>= 1) != 0
                b += a & 1
                c += 1
            end
            A[n+1] = A[n] + <<(b, 1) - c
        end
        A
    end; println(A268289List(61)) # Peter Luschny, Jun 22 2020
  • Maple
    a000120 := proc(n) add(i, i=convert(n, base, 2)) end:
    a023416 := proc(n) if n = 0 then 1; else add(1-e, e=convert(n, base, 2)) ; end if; end proc:
    a268289:=proc(n) option remember; global a000120, a023416;
    if n=0 then 0 else a268289(n-1)+a000120(n)-a023416(n); fi; end;
    [seq(a268289(n),n=0..132)];
    # N. J. A. Sloane, Mar 07 2016
    # second Maple program:
    a:= proc(n) option remember; `if`(n<0, 0,
          a(n-1)+add(2*i-1, i=Bits[Split](n)))
        end:
    seq(a(n), n=0..60);  # Alois P. Heinz, Jan 18 2022
  • Mathematica
    Join[{0}, Table[DigitCount[n, 2, 1] - DigitCount[n, 2, 0], {n, 1, 100}] // Accumulate] (* Jean-François Alcover, Oct 24 2016 *)
  • PARI
    a(n) = if (n==0, 0, if (n%2, 2*a((n-1)/2)+1, a(n/2) + a(n/2-1))); \\ Michel Marcus, Jun 16 2020
    
  • PARI
    a(n) = my(v=binary(n+1),s=-1); for(i=1,#v, v[i]=if(v[i],s++,s--;1)); fromdigits(v,2); \\ Kevin Ryde, Jun 16 2020
    
  • Python
    def A268289(n): return (sum(i.bit_count() for i in range(1,n+1))<<1)-1-(n+1)*(m:=(n+1).bit_length())+(1<Chai Wah Wu, Mar 01 2023
    
  • Python
    def A268289(n): return sum((n+1)%m if (n+1)&(m:=1<Chai Wah Wu, Nov 11 2024
    

Formula

From N. J. A. Sloane, Mar 11 2016: (Start)
a(0)=0; for n > 0, a(n) = a(n-1) + A000120(n) - A023416(n) = A000788(n) - A181132(n).
a(0)=0; thereafter a(2*n) = a(n) + a(n-1), a(2*n+1) = 2*a(n) + 1.
G.f.: (1/(1-x)^2) * Sum_{k >= 0} x^(2^k)*(1-x^(2^k))/(1+x^(2^k)).
a(2^k-1) = 2^k-1, a(3*2^k-1) = 2^(k+1)-1, a(5*2^k-1) = 3*2^k-1, etc.
(End)
From Laura Monroe, Jun 11 2020: (Start)
a(n-1) = Sum_{i=0..floor(log_2(n))} (((floor(n/(2^i))+1) mod 2)*(2^i)+(-1)^((floor(n/(2^i))+1) mod 2)*(n mod (2^i))), for n>=1.
This is an explicit formula for this sequence, and is O(log(n)). This formula is proven in Prop. 18, in the Monroe et al. reference in the links. (End)
From Laura Monroe, Oct 23 2020: (Start)
a(n) = n - A296062(n).
a(n+1) = (n+1) - (2^k)*tau(x/(2^k)), where tau is the Takagi function and n+1 = (2^k)+x with x < 2^k. (End)

Extensions

Simplified definition following a suggestion from Michel Marcus. Corrected start, added more terms. - N. J. A. Sloane, Mar 07 2016
Showing 1-10 of 25 results. Next