login
a(n) = (number of primes p in the first n primes such that 2*p+1 is also prime) - (number of primes p in the first n primes such that 2*p-1 is also prime).
1

%I #26 Jul 09 2022 11:13:14

%S 0,0,1,0,1,1,1,0,1,2,1,0,1,1,1,2,2,2,2,2,2,1,2,3,2,2,2,2,2,3,3,4,4,3,

%T 3,3,2,2,2,3,4,4,5,5,5,4,3,3,3,2,3,4,4,5,5,5,5,4,4,5,5,6,5,5,5,5,4,3,

%U 3,3,3,4,3,3,2,2,2,2,2,2,3,3,4,4,3,4,4,4,4,4,4,4,4,5,4,4,5,5,5

%N a(n) = (number of primes p in the first n primes such that 2*p+1 is also prime) - (number of primes p in the first n primes such that 2*p-1 is also prime).

%C a(n) is the number of members of A005384 <= prime(n) minus the number of members of A005382 <= prime(n).

%H Robert Israel, <a href="/A353048/b353048.txt">Table of n, a(n) for n = 1..10000</a>

%H T. Haddad, <a href="http://hdl.handle.net/1866/25109">Prime Number Races</a>, Université de Montréal master's thesis, 2020.

%H Robert Israel, <a href="/A353048/a353048.png">Plot of (n, a(n)) for n = 1..10^6</a>

%e Of the first 5 primes there are 4 (2, 3, 5 and 11) such that 2*p+1 is prime and 3 (2, 3 and 7) such that 2*p-1 is prime, so a(5) = 4 - 3 = 1.

%p f:= proc(p) `if`(isprime(2*p+1),1,0) - `if`(isprime(2*p-1),1,0) end proc:

%p L:= map(f, [seq(ithprime(i),i=1..200)]):

%p ListTools:-PartialSums(L);

%t Accumulate[(Boole[PrimeQ[2*# + 1]] - Boole[PrimeQ[2*# - 1]]) & /@ Prime[Range[100]]] (* _Amiram Eldar_, Apr 20 2022 *)

%o (Python)

%o from itertools import accumulate

%o from sympy import isprime, prime, primerange

%o def f(p): return isprime(2*p+1) - isprime(2*p-1)

%o def aupton(nn): return list(accumulate(map(f, primerange(2, prime(nn)+1))))

%o print(aupton(99)) # _Michael S. Branicky_, Apr 20 2022

%o (PARI) a(n) = my(vp=primes(n)); sum(k=1, n, isprime(2*vp[k]+1)-isprime(2*vp[k]-1)); \\ _Michel Marcus_, Apr 21 2022

%Y Cf. A005382, A005384.

%K sign

%O 1,10

%A _J. M. Bergot_ and _Robert Israel_, Apr 20 2022