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.

A308430 Number of 0's minus number of 1's among the edge truncated binary representations of the first n prime numbers.

This page as a plain text file.
%I A308430 #38 Dec 27 2024 18:30:21
%S A308430 0,0,1,0,0,0,3,4,3,2,-1,1,3,3,1,1,-1,-3,0,1,4,3,4,5,8,9,8,7,6,7,2,6,
%T A308430 10,12,14,14,14,16,16,16,16,16,12,16,18,18,18,14,14,14,14,10,10,6,13,
%U A308430 16,19,20,23,26,27,30,31,30,31,30,31,34,33,32,35,34,31,30,27,22,25,26,29,30,31,32,29,30,27,24,27,28,27,24,23,18,15,12,9,4,-1,5,9,11
%N A308430 Number of 0's minus number of 1's among the edge truncated binary representations of the first n prime numbers.
%C A308430 By "edge truncated" we mean removing the first and last digit. For prime(3)=5 which has binary representation 101 edge truncating yields the string '0'. If there are 2 digits, then edge truncation yields the empty string ''. We count zero 1's and zero 0's in the empty string. The only cases of this are prime(1)=2 and prime(2)=3 which have binary representations 10 and 11.
%H A308430 Rémy Sigrist, <a href="/A308430/b308430.txt">Table of n, a(n) for n = 1..12251</a>
%H A308430 Sean A. Irvine, <a href="https://github.com/archmageirvine/joeis/blob/master/src/irvine/oeis/a308/A308430.java">Java program</a> (github)
%H A308430 Jonas K. Sønsteby, <a href="/A308430/a308430_10.png">Graph of 200 terms.</a>
%H A308430 Jonas K. Sønsteby, <a href="/A308430/a308430_11.png">Graph of 1000 terms.</a>
%H A308430 Jonas K. Sønsteby, <a href="/A308430/a308430_12.png">Graph of 5000 terms.</a>
%H A308430 Jonas K. Sønsteby, <a href="/A308430/a308430_13.png">Graph of 10000 terms.</a>
%H A308430 Jonas K. Sønsteby, <a href="/A308430/a308430_14.png">Graph of 100000 terms.</a>
%F A308430 a(n) = a(n-1) + bitlength(prime(n)_2) - 2 * popcount(prime(n)_2) + 2, n > 1. - _Sean A. Irvine_, May 27 2019
%F A308430 a(n) = Sum_{k=2..n} (A035100(k) - 2*A014499(k) + 2) = Sum_{k=2..n} (A070939(A000040(k)) - 2*A000120(A000040(k)) + 2). - _Daniel Suteu_, Jul 13 2019
%o A308430 (Python)
%o A308430 import gmpy2
%o A308430 def dec2bin(x):
%o A308430     return str(bin(x))[2:]
%o A308430 def digitBalance(string):
%o A308430     s = 0
%o A308430     for char in string:
%o A308430         if int(char) > 0:
%o A308430             s -= 1
%o A308430         else:
%o A308430             s += 1
%o A308430     return s
%o A308430 N = 100 # number of terms
%o A308430 seq = [0]
%o A308430 prime = 2
%o A308430 for i in range(N-1):
%o A308430     prime = gmpy2.next_prime(prime)
%o A308430     binary = dec2bin(prime)
%o A308430     truncated = binary[1:-1]
%o A308430     term = seq[-1] + digitBalance(truncated)
%o A308430     seq.append(term)
%o A308430 print(seq) # _Jonas K. Sønsteby_, May 27 2019
%o A308430 (PARI) s=0; forprime (p=2, 541, print1 (s += #binary(p\2)+1-2*hammingweight(p\2) ", ")) \\ _Rémy Sigrist_, Jul 13 2019
%o A308430 (Sage)
%o A308430 def A308430list(b):
%o A308430     L = []; s = 0
%o A308430     for p in prime_range(2, b):
%o A308430         q = (p//2).digits(2)
%o A308430         s += 1 + len(q) - 2*sum(q)
%o A308430         L.append(s)
%o A308430     return L
%o A308430 print(A308430list(542)) # _Peter Luschny_, Jul 13 2019
%Y A308430 Cf. A004676, A095375, A014499, A177718, A296062.
%K A308430 sign,base,look
%O A308430 1,7
%A A308430 _Andrea Fornaciari_, May 26 2019