login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

Let A_n be a square n X n matrix with entries A_n(i,j)=1 if i+j is prime, and A_n(i,j)=0 otherwise. Then a(n) counts the 1's in A_n.
2

%I #50 Dec 09 2023 09:11:39

%S 1,3,5,9,11,15,19,23,29,37,43,51,57,63,71,81,89,97,105,113,123,135,

%T 145,157,169,181,195,209,221,235,249,263,277,293,309,327,345,363,381,

%U 401,419,439,457,475,495,515,533,551,571,591,613,637,659,683,709,735

%N Let A_n be a square n X n matrix with entries A_n(i,j)=1 if i+j is prime, and A_n(i,j)=0 otherwise. Then a(n) counts the 1's in A_n.

%C Bertrand's postulate guarantees for every integer n the existence of at least one prime q with n < q < 2n. Equivalently, A(n) has at least one skew diagonal below the main skew diagonal whose entries will be equal to 1.

%H David A. Corneth, <a href="/A292918/b292918.txt">Table of n, a(n) for n = 1..10000</a>

%H William Dowling and Nadia Lafreniere, <a href="https://arxiv.org/abs/2312.02383">Homomesy on permutations with toggling actions</a>, arXiv:2312.02383 [math.CO], 2023. See page 10.

%F From _Alois P. Heinz_, Sep 29 2017: (Start)

%F a(n) = a(n-1) + 2 * (pi(2*n-1) - pi(n)) for n > 1, a(1) = 1.

%F a(n) = A069879(n) + 1 = 2*A071917(n) + 1. (End)

%F a(n) = Sum_{i=1..n} (pi(n+i) - pi(i)), where pi = A000720. - _Ridouane Oudra_, Aug 29 2019

%F a(n) = Sum_{p <= 2n+1, p prime} min(p-1, 2n+1-p). - _Ridouane Oudra_, Oct 30 2023

%e |1 1 0 1 0|

%e |1 0 1 0 1|

%e A_5 = |0 1 0 1 0| and so a(5) = 11.

%e |1 0 1 0 0|

%e |0 1 0 0 0|

%p with(numtheory):

%p a:= proc(n) option remember; `if`(n=1, 1,

%p a(n-1)+2*(pi(2*n-1)-pi(n)))

%p end:

%p seq(a(n), n=1..80); # _Alois P. Heinz_, Sep 29 2017

%t A[n_] := Table[Boole[PrimeQ[i + j]], {i, 1, n}, {j, 1, n}]; a[n_] := Count[Flatten[A[n]], 1];

%t (* or, after _Alois P. Heinz_ (200 times faster): *)

%t a[1] = 1; a[n_] := a[n] = a[n-1] + 2(PrimePi[2n-1] - PrimePi[n]);

%t Array[a, 80] (* _Jean-François Alcover_, Sep 29 2017 *)

%o (Python)

%o from sympy import primepi

%o from sympy.core.cache import cacheit

%o @cacheit

%o def a(n): return 1 if n==1 else a(n - 1) + 2*(primepi(2*n - 1) - primepi(n))

%o print([a(n) for n in range(1, 51)]) # _Indranil Ghosh_, Dec 13 2017, after _Alois P. Heinz_

%o (Magma) sol:=[]; for n in [1..56] do k:=0; for i,j in [1..n] do if IsPrime(i+j) then k:=k+1; end if; end for; Append(~sol,k);end for; sol; // _Marius A. Burtea_, Aug 29 2019

%o (PARI) first(n) = {my(res = vector(n), pn = 0, p2n1 = 1); res[1] = 1; for(i = 2, n,

%o if(isprime(i), pn++); if(isprime(2*i-1), p2n1++); res[i] = res[i-1] + 2*(p2n1 - pn)); res} \\ _David A. Corneth_, Aug 31 2019

%Y Cf. A000040, A000720, A069879, A071917.

%K nonn

%O 1,2

%A _Anthony Hernandez_, Sep 26 2017