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 11 results. Next

A095018 a(n) is the number of primes p which have exactly n zeros and n ones when written in binary.

Original entry on oeis.org

1, 0, 2, 4, 17, 28, 189, 531, 1990, 5747, 23902, 76658, 291478, 982793, 3677580, 13214719, 49161612, 177190667, 664806798, 2443387945
Offset: 1

Views

Author

Antti Karttunen, Jun 01 2004

Keywords

Comments

a(n) is the number of terms in A066196 which lie between 2^(2n-1) and 2^2n inclusively.

Examples

			a(1) = 1 since only 2_10 = 10_2 satisfies the criterion;
a(2) = 0 since there is no prime between 4 and 16 which meets the criterion.
The only primes in the range ]2^5,2^6[ with equal numbers of ones and zeros in their binary expansion are 37 (in binary 100101) and 41 (in binary 101011) thus a(3)=2.
a(4) = 4 since 139, 149, 163 and 197 meet the criterion; etc.
		

Crossrefs

Programs

  • Mathematica
    f[n_] := Block[{c = 0, p = NextPrime[2^(2n -1) -1], lmt = 2^(2n)}, While[p < lmt, If[DigitCount[p, 2, 1] == n, c++]; p = NextPrime@ p]; c]; Array[f, 17] (* K. D. Bajpai and Robert G. Wilson v, Jan 10 2017 *)
  • Python
    from itertools import combinations
    from sympy import isprime
    def A095018(n): return sum(1 for d in combinations((1<Chai Wah Wu, Jul 18 2025

Extensions

Edited by N. J. A. Sloane, Jan 16 2017
a(18)-a(20) from Amiram Eldar, Nov 21 2020

A372516 Number of ones minus number of zeros in the binary expansion of the n-th prime number.

Original entry on oeis.org

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

Author

Gus Wiseman, May 13 2024

Keywords

Comments

Absolute value is A177718.

Examples

			The binary expansion of 83 is (1,0,1,0,0,1,1), and 83 is the 23rd prime, so a(23) = 4 - 3 = 1.
		

Crossrefs

The sum instead of difference is A035100, firsts A372684 (primes A104080).
The negative version is A037861(A000040(n)).
Restriction of A145037 to the primes.
The unsigned version is A177718.
- Positions of zeros are A177796, indices of the primes A066196.
- Positions of positive terms are indices of the primes A095070.
- Positions of negative terms are indices of the primes A095071.
- Positions of negative ones are A372539, indices of the primes A095072.
- Positions of ones are A372538, indices of the primes A095073.
- Positions of nonnegative terms are indices of the primes A095074.
- Positions of nonpositive terms are indices of the primes A095075.
A000120 counts ones in binary expansion (binary weight), zeros A080791.
A030190 gives binary expansion, reversed A030308.
A035103 counts zeros in binary expansion of primes, firsts A372474.
A048793 lists binary indices, reverse A272020, sum A029931.
A070939 gives length of binary expansion.
A101211 lists run-lengths in binary expansion, row-lengths A069010.
A372471 lists the binary indices of each prime.

Programs

  • Mathematica
    Table[DigitCount[Prime[n],2,1]-DigitCount[Prime[n],2,0],{n,100}]
    DigitCount[#,2,1]-DigitCount[#,2,0]&/@Prime[Range[100]] (* Harvey P. Dale, May 09 2025 *)

Formula

a(n) = A000120(A000040(n)) - A080791(A000040(n)).
a(n) = A014499(n) - A035103(n).
a(n) = A145037(A000040(n))

A372538 Numbers k such that the number of ones minus the number of zeros in the binary expansion of the k-th prime number is 1.

Original entry on oeis.org

3, 8, 20, 23, 24, 26, 30, 58, 61, 63, 65, 67, 78, 80, 81, 82, 84, 88, 185, 187, 194, 200, 201, 203, 213, 214, 215, 221, 225, 226, 227, 234, 237, 246, 249, 253, 255, 256, 257, 259, 266, 270, 280, 284, 287, 290, 573, 578, 586, 588, 591, 593, 611, 614, 615, 626
Offset: 1

Author

Gus Wiseman, May 13 2024

Keywords

Examples

			The binary expansion of 83 is (1,0,1,0,0,1,1) with ones minus zeros 4 - 3 = 1, and 83 is the 23rd prime, so 23 is in the sequence.
The primes A000040(a(n)) together with their binary expansions and binary indices begin:
     5:           101 ~ {1,3}
    19:         10011 ~ {1,2,5}
    71:       1000111 ~ {1,2,3,7}
    83:       1010011 ~ {1,2,5,7}
    89:       1011001 ~ {1,4,5,7}
   101:       1100101 ~ {1,3,6,7}
   113:       1110001 ~ {1,5,6,7}
   271:     100001111 ~ {1,2,3,4,9}
   283:     100011011 ~ {1,2,4,5,9}
   307:     100110011 ~ {1,2,5,6,9}
   313:     100111001 ~ {1,4,5,6,9}
   331:     101001011 ~ {1,2,4,7,9}
   397:     110001101 ~ {1,3,4,8,9}
   409:     110011001 ~ {1,4,5,8,9}
   419:     110100011 ~ {1,2,6,8,9}
   421:     110100101 ~ {1,3,6,8,9}
   433:     110110001 ~ {1,5,6,8,9}
   457:     111001001 ~ {1,4,7,8,9}
  1103:   10001001111 ~ {1,2,3,4,7,11}
  1117:   10001011101 ~ {1,3,4,5,7,11}
  1181:   10010011101 ~ {1,3,4,5,8,11}
  1223:   10011000111 ~ {1,2,3,7,8,11}
		

Crossrefs

Restriction of A031448 to the primes, positions of ones in A145037.
Taking primes gives A095073, negative A095072.
Positions of ones in A372516, absolute value A177718.
A000120 counts ones in binary expansion (binary weight), zeros A080791.
A030190 gives binary expansion, reversed A030308.
A035103 counts zeros in binary expansion of primes, firsts A372474.
A048793 lists binary indices, reverse A272020, sum A029931.
A070939 gives the length of an integer's binary expansion.
A101211 lists run-lengths in binary expansion, row-lengths A069010.
A372471 lists binary indices of primes.

Programs

  • Mathematica
    Select[Range[1000],DigitCount[Prime[#],2,1]-DigitCount[Prime[#],2,0]==1&]

A280872 Primes that have exactly 7 zeros and 7 ones in their binary expansion.

Original entry on oeis.org

8287, 8311, 8317, 8423, 8429, 8527, 8539, 8563, 8599, 8627, 8629, 8647, 8677, 8681, 8689, 8783, 8807, 8819, 8821, 8861, 8933, 8999, 9011, 9013, 9043, 9049, 9059, 9109, 9137, 9157, 9161, 9277, 9319, 9323, 9337, 9371, 9397, 9419, 9421, 9433, 9511, 9547, 9613, 9619
Offset: 1

Author

K. D. Bajpai, Jan 09 2017

Keywords

Examples

			8287 is in the sequence because it is a prime and its binary expansion 10000001011111 contains exactly 7 zeros and 7 ones.
9161 is in the sequence because it is a prime and its binary expansion 10001111001001 contains exactly 7 zeros and 7 ones.
		

Crossrefs

Programs

  • Maple
    select(t -> isprime(t) and convert(convert(t,base,2),`+`)=7, [seq(i,i=2^13+1..2^14-1,2)]); # Robert Israel, Jan 09 2017
  • Mathematica
    Select[Prime[Range[50000]], Count[IntegerDigits[#, 2], 0] == Count[IntegerDigits[#, 2], 1] == 7 &]
    Select[FromDigits[#,2]&/@(Join[{1},#]&/@Permutations[ {1,1,1,1,1,1,0,0,0,0,0,0,0}]),PrimeQ]//Union (* Harvey P. Dale, May 10 2019 *)

A337258 Primes p such that p and the prime next to p are both digitally balanced numbers in base 2 (A031443).

Original entry on oeis.org

37, 139, 557, 563, 613, 647, 653, 659, 2389, 2467, 2699, 2851, 8311, 8423, 8627, 8677, 8681, 8807, 8819, 9011, 9043, 9049, 9157, 9319, 9323, 9419, 9613, 9803, 9811, 9817, 9829, 9923, 10331, 10343, 10453, 10597, 11279, 11317, 11353, 11399, 11587, 11783, 11789
Offset: 1

Author

Amiram Eldar, Nov 21 2020

Keywords

Comments

Prime p such that p and the prime next to p are both terms of A066196.

Examples

			37 is a term since it is a prime number, and both 37 and the next prime, 41, are digitally balanced in base 2: the binary representation of 37 is 100101, the binary representation of 41 is 101001, and both contain 3 0's and 3 1's.
		

Crossrefs

Programs

  • Mathematica
    digBalQ[n_] := Module[{d = IntegerDigits[n, 2], m}, EvenQ@(m = Length@d) && Count[d, 1] == m/2]; p = Select[Range[3*10^4], PrimeQ]; p[[Position[Partition[digBalQ /@ p, 2, 1], {True, True}] // Flatten]]

A345395 Composite numbers whose divisors that are larger than 1 are all digitally balanced numbers in base 2 (A031443).

Original entry on oeis.org

132061, 138421, 151427, 532393, 545269, 546407, 557983, 559609, 568801, 570709, 573193, 579013, 590687, 595853, 599707, 604873, 610777, 624553, 630293, 635213, 2102767, 2105063, 2109383, 2111339, 2123677, 2128187, 2129081, 2129609, 2143961, 2149753, 2151131, 2151661
Offset: 1

Author

Amiram Eldar, Jun 17 2021

Keywords

Comments

The prime numbers with this property are the digitally balanced primes (A066196).
All the terms are odd, since if k is an even digitally balanced number then its divisor k/2 is not digitally balanced (since it has one fewer 0 in its binary expansion).
Apparently most of the terms are semiprimes (A001358) with 4 divisors.
Terms with 3 divisors, i.e., squares of primes: 145178401 = 12049^2, 155575729 = 12473^2, ...
The least term with more than 4 divisors is 8897396239 = 163 * 929 * 58757, with 8 divisors.
The least term with 6 divisors is 8923691369 = 41 * 14753^2.

Examples

			132061 is a term since its divisors that are larger than 1 are {41, 3221, 132061}, and their binary representations are {101001, 110010010101, 100000001111011101}. Each one has an equal number of 0's and 1's.
		

Crossrefs

Subsequence of A031443.
Cf. A066196.

Programs

  • Mathematica
    balQ[n_] := Module[{d = IntegerDigits[n, 2], m}, EvenQ @ (m = Length @ d) && Count[d, 1] == m/2]; Select[Range[9,10^6,2], CompositeQ[#] && AllTrue[Rest@Divisors[#], balQ] &]
  • PARI
    isbal(k) = exponent(k) + 1 == 2 * hammingweight(k);
    isok(k) = if(k == 1 || isprime(k), 0, fordiv(k, d, if(d > 1 && !isbal(d), return(0))); 1); \\ Amiram Eldar, Jul 03 2025

A280997 Primes that have exactly 3 ones in both their binary and ternary expansions.

Original entry on oeis.org

13, 37, 41, 67, 97, 131, 193, 577, 1033, 1153, 2053, 4129, 8209, 18433, 32771, 32801, 32833, 65539, 133121, 525313, 557057, 1049089, 4194433, 167772161, 268435459
Offset: 1

Author

K. D. Bajpai, Jan 12 2017

Keywords

Comments

Sequence is likely to be finite. If it exists, a(26) > 10^200. - Robert Israel, Jan 12 2017

Examples

			37 is in the sequence because it is a prime and its binary expansion 100101 and ternary expansion 1101 both have exactly 3 ones.
131 is in the sequence because it is a prime and its binary expansion 10000011 and ternary expansion 11212 both have exactly 3 ones.
		

Crossrefs

Programs

  • Maple
    A:= NULL:
    for a from 2 to 100 do
      for b from 1 to a-1 do
        p:= 2^a + 2^b + 1;
        if numboccur(1, convert(p,base,3)) = 3 and isprime(p) then
          A:= A, p
        fi
    od od:
    A; # Robert Israel, Jan 12 2017
  • Mathematica
    Select[Prime[Range[500000]], Count[IntegerDigits[#, 3], 1] == Count[IntegerDigits[#, 2], 1] == 3 &]
    Select[Prime[Range[300000]],DigitCount[#,2,1]==DigitCount[#,3,1]==3&] (* The program generates the first 23 terms of the sequence. *) (* Harvey P. Dale, Jul 20 2025 *)

A345396 a(n) is the least prime p such that {p, p^2, ..., p^n} are all digitally balanced numbers in base 2 (A031443).

Original entry on oeis.org

2, 12049, 52673, 937253, 1000099, 3844790441, 62911443401, 1052000152157
Offset: 1

Author

Amiram Eldar, Jun 17 2021

Keywords

Comments

a(9) > 2.5 * 10^12, if it exists.

Examples

			a(1) = 2 since 2 is digitally balanced: its binary representation, 10, has the same number of 0's and 1's.
a(2) = 12049 since both 12049 and 12049^2 are digitally balanced: the binary representation of 12049, 10111100010001, has 7 0's and 7 1's, and the binary representation of 12049^2, 1000101001110011111100100001, has 14 0's and 14 1's.
		

Crossrefs

Subsequence of A031443, A066196 and A345395.
Cf. A345397.

Programs

  • Mathematica
    balQ[n_] := Module[{d = IntegerDigits[n, 2], m}, EvenQ @ (m = Length @ d) && Count[d, 1] == m/2]; f[p_] := Module[{e = 0, r = p}, While[balQ[r], r *= p; e++]; e]; mx = 5; s = Table[0, {mx}]; c = 0; p = 2; While[c < mx, k = f[p]; Do[If[s[[i]] == 0, s[[i]] = p; c++], {i, 1, k}]; p = NextPrime[p]]; s
  • Python
    from itertools import count, islice
    from sympy import isprime
    from sympy.utilities.iterables import multiset_permutations
    def isbalanced(n): b = bin(n)[2:]; return b.count("0") == b.count("1")
    def A066196gen():
        yield from filter(isprime, (int("1"+"".join(p), 2) for n in count(1) for p in multiset_permutations("0"*n+"1"*(n-1))))
    def a(n):
        for p in A066196gen():
            if all(isbalanced(p**i) for i in range(2, n+1)):
                return p
    print([a(n) for n in range(1, 6)]) # Michael S. Branicky, May 15 2022

A174976 Primes which have an equal number of 0,1,2 in their Base_3 expansion.

Original entry on oeis.org

11, 19, 6719, 6791, 6793, 6857, 6883, 6911, 6947, 6959, 6983, 6991, 7001, 7013, 7027, 7039, 7151, 7187, 7193, 7243, 7247, 7369, 7433, 7477, 7487, 7499, 7517, 7559, 7607, 7703, 7793, 7823, 7841, 7877, 7949, 7993, 8069, 8087, 8089, 8117, 8123, 8147, 8161
Offset: 1

Author

Keywords

Comments

IntegerDigits[11,3] -> 1,0,2, IntegerDigits[19,3] -> 2,0,1, IntegerDigits[6791,3] -> 1,0,0,0,2,2,1,1,2,...

Crossrefs

Programs

  • Mathematica
    Prime[Select[Range[7! ],Count[IntegerDigits[Prime[ # ],3],0]==Count[IntegerDigits[Prime[ # ],3],1]==Count[IntegerDigits[Prime[ # ],3],2]&]]

A337306 a(n) is the least start of a run of exactly n consecutive prime numbers which are digitally balanced numbers in base 2 (A031443).

Original entry on oeis.org

2, 37, 557, 647, 9803, 192583, 698653, 150287, 34449209, 136017109, 191058199, 618408991, 564779279, 40434774727, 52195951979, 149416079731, 598718776379, 802636910771
Offset: 1

Author

Amiram Eldar, Nov 21 2020

Keywords

Examples

			a(1) = 2 since 2 is a prime and a digitally balanced number and the next prime, 3, is not.
a(2) = 37 since 37 is a prime, 37 and the next prime, 41, are both digitally balanced in base 2, and the primes previous to 37 (31) and next to 41 (43) are not.
		

Crossrefs

Programs

  • Mathematica
    digBalQ[n_] := Module[{d = IntegerDigits[n, 2], m}, EvenQ@(m = Length@d) && Count[d, 1] == m/2]; s[max_] := Module[{seq = Table[0, {max}], count = 0, p = 2, pp, n}, While[count < max, If[digBalQ[p], pp = NextPrime[p]; n = 1; While[digBalQ[pp], n++; pp = NextPrime[pp]]; If[n <= max && seq[[n]] == 0, count++; seq[[n]] = p]; p = NextPrime[pp], p = NextPrime[p]]]; seq]; s[8]
Showing 1-10 of 11 results. Next