OFFSET
1,2
COMMENTS
Similar sequences given in cross-references have further information and references; in particular A273257 has much more efficient PARI code. - M. F. Hasler, Jun 27 2019
LINKS
Chai Wah Wu, Table of n, a(n) for n = 1..7944
Jon S. Birdsey, Geza Schay, A Sieve for Twin Primes, arXiv:1906.09220 [math.NT], 2019.
EXAMPLE
There is a single twin prime (3) between 2 and 4, so a(1) = 1.
There are 3 twin primes (3, 5 and 7) between 3 and 9, so a(2) = 3.
MAPLE
a:= n-> (p-> add(`if`(isprime(j) and (isprime(j-2) or
isprime(j+2)), 1, 0), j=p..p^2))(ithprime(n)):
seq(a(n), n=1..55); # Alois P. Heinz, Jun 25 2019
MATHEMATICA
a[n_] := With[{p = Prime[n]}, Sum[Boole[PrimeQ[k] && (PrimeQ[k-2] || PrimeQ[k+2])], {k, p, p^2}]];
Array[a, 55] (* Jean-François Alcover, Feb 29 2020 *)
PROG
(PARI) a(n) = my(p=prime(n)); sum(k=p, p^2, isprime(k) && (isprime(k-2) || isprime(k+2)));
(Python)
from sympy import prime, prevprime, nextprime
def A308777(n):
if n == 1:
return 1
c, p = 0, prime(n)
p2, x = p**2, [prevprime(p), p , nextprime(p)]
while x[1] <= p2:
if x[1] - x[0] == 2 or x[2] - x[1] == 2:
c += 1
x = x[1:] + [nextprime(x[2])]
return c # Chai Wah Wu, Jun 25 2019
CROSSREFS
KEYWORD
nonn
AUTHOR
Michel Marcus, Jun 24 2019
STATUS
approved