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.

A065081 Alternating bit sum (A065359) for n-th prime p: replace 2^k with (-1)^k in binary expansion of p.

Original entry on oeis.org

-1, 0, 2, 1, -1, 1, 2, 1, 2, 2, 1, 1, -1, -2, -1, 2, -1, 1, 1, 2, 1, 1, 2, 2, 1, 2, 1, -1, 1, 2, 1, -1, -1, -2, 2, 1, 1, -2, -1, -1, -1, 1, -1, 1, 2, 1, 1, 1, -1, 1, -1, -1, 1, -1, 2, 2, 2, 1, 4, 2, 1, 2, 1, 2, 1, 2, 1, 4, 2, 4, 2, 2, 1, 4, 1, 2, 2, 1, 2, 1, -1, 1, -1, 1, 1, -1, 2, 1, 2, 1, 2, 2, 1, -1, 1, 2, 2, -1, -2, 1
Offset: 1

Views

Author

Robert G. Wilson v, Nov 09 2001

Keywords

Comments

Only 3d = 11b has an alternating sum of 0.

Examples

			The sixth prime is 13d = 1101b -> -(1)+(1)-(0)+(1) = 1 = a(6)
		

Crossrefs

Cf. A065359.

Programs

  • Mathematica
    f[n_] := (d = Reverse[ IntegerDigits[n, 2]]; l = Length[d]; s = 0; k = 1; While[k < l + 1, s = s - (-1)^k*d[[k]]; k++ ]; s); Table[ Prime[ f[n]], {n, 1, 100} ]
  • PARI
    baseE(x, b)=
    {
      local(d, e=0, f=1);
      while (x>0, d=x-b*(x\b); x\=b; e+=d*f; f*=10);
      return(e)
    }
    SumAD(x)=
    {
      local(a=1, s=0);
      while (x>9, s+=a*(x-10*(x\10)); x\=10; a=-a);
      return(s + a*x)
    }
    { for (n=1, 1000, p=prime(n);
      s=SumAD(baseE(p, 2)); write("b065081.txt", n, " ", s) )
    } \\ Harry J. Smith, Oct 06 2009
    
  • PARI
    f(p)=
    {
      v=binary(p);
      L=#v; u=1; s=0;
      forstep(k=L,1,-1, if(v[k]==1,s+=u); u=-u;);
      return(s)
    };
    for(n=1,100,p=prime(n); an=f(p);print1(an,", ")) \\ Washington Bomfim, Jan 16 2011
    
  • Python
    from sympy.ntheory import digits, prime
    def A065081(n): return sum((0,1,-1,0)[i] for i in digits(prime(n),4)[1:]) # Chai Wah Wu, Jul 19 2024