login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

An alternating sum of all numbers from the n-th up to the (n+1)st isolated prime.
3

%I #14 Nov 30 2021 08:41:14

%S 11,30,42,50,60,73,81,86,93,105,120,129,144,160,165,170,192,217,228,

%T 242,254,260,270,285,300,312,324,334,345,356,363,370,376,381,386,393,

%U 399,405,424,441,446,453,462,473,483,489,495,501,506,525,544,552,560

%N An alternating sum of all numbers from the n-th up to the (n+1)st isolated prime.

%C 11 followed by the average of each two consecutive non-twin primes. - _Colin Barker_, Jul 17 2014

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

%F a(n) = sum_{j= A007510(n).. A007510(n+1)} (-1)^(j+1)*j = A001057(A007510(n+1))-A001057(A007510(n)-1).

%e a(1) = -2+3-4+5-6+7-8+9-10+11-12+13-14+15-16+17-18+19-20+21-22+23 = 11.

%e a(2) = 23-24+25-26+27-28+29-30+31-32+33-34+35-36+37 = 30.

%p N:= 1000: # to get all terms where the larger non-twin <= N

%p Primes:= select(isprime,{seq(2*i-1,i=1..floor((N+1)/2))}):

%p NonTwins:= Primes minus (map(t->t+2,Primes) union map(t->t-2,Primes)):

%p 11, seq((NonTwins[i]+NonTwins[i+1])/2,i=1..nops(NonTwins)-1); # _Robert Israel_, Jul 21 2014

%o (PARI)

%o non_twin_primes(pmax) = my(s=[]); forprime(p=2, pmax, if(!isprime(p-2) && !isprime(p+2), s=concat(s, p))); s

%o a162734(maxp) = my(ntp=non_twin_primes(maxp)); vector(#ntp-1, n, sum(k=ntp[n], ntp[n+1], -k*(-1)^k))

%o a162734(500) \\ _Colin Barker_, Jul 17 2014

%o (Python)

%o from sympy import isprime, primerange

%o def nontwins(N):

%o return [p for p in primerange(1, N+1) if not (isprime(p-2) or isprime(p+2))]

%o def auptont(N): # all terms where the larger non-twin <= N

%o nt = nontwins(N)

%o return [sum((-1)**(j+1)*j for j in range(nt[i], nt[i+1]+1)) for i in range(len(nt)-1)]

%o print(auptont(565)) # _Michael S. Branicky_, Nov 30 2021

%Y Cf. A007510.

%K nonn,less

%O 1,1

%A _Juri-Stepan Gerasimov_, Jul 13 2009

%E Replaced 55 by 60 and 447 by 446 - _R. J. Mathar_, Sep 23 2009