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.

A130911 a(n) is the number of primes with odd binary weight among the first n primes minus the number with an even binary weight.

Original entry on oeis.org

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

Views

Author

T. D. Noe, Jun 08 2007

Keywords

Comments

Prime race between evil primes (A027699) and odious primes (A027697).
Shevelev conjectures that a(n) >= 0 for n > 3. Surprisingly, the conjecture also appears to be true if we count zeros instead of ones in the binary representation of prime numbers.
The conjecture is true for primes up to at least 10^13. Mauduit and Rivat prove that half of all primes are evil. - T. D. Noe, Feb 09 2009

Crossrefs

Cf. A156549 (race between primes having an odd/even number of zeros in binary).

Programs

  • Mathematica
    cnt=0; Table[p=Prime[n]; If[EvenQ[Count[IntegerDigits[p,2],1]], cnt--, cnt++ ]; cnt, {n,10000}]
    Accumulate[If[OddQ[DigitCount[#,2,1]],1,-1]&/@Prime[Range[100]]] (* Harvey P. Dale, Aug 09 2013 *)
  • PARI
    f(p)={v=binary(p);s=0;for(k=1,#v,if(v[k]==1,s++)); return(s%2)};nO=0;nE=0;forprime(p=2,520,if(f(p),nO++, nE++);an=nO-nE;print1(an,", ")) \\ Washington Bomfim, Jan 14 2011
    
  • Python
    from sympy import nextprime
    from itertools import islice
    def agen():
        p, evod = 2, [0, 1]
        while True:
            yield evod[1] - evod[0]
            p = nextprime(p); evod[bin(p).count('1')%2] += 1
    print(list(islice(agen(), 97))) # Michael S. Branicky, Dec 21 2021

Formula

a(n) = (number of odious primes <= prime(n)) - (number of evil primes <= prime(n)).
a(n) = A200247(n) - A200246(n).

Extensions

Edited by N. J. A. Sloane, Nov 16 2011