A008347 a(n) = Sum_{i=0..n-1} (-1)^i * prime(n-i).
0, 2, 1, 4, 3, 8, 5, 12, 7, 16, 13, 18, 19, 22, 21, 26, 27, 32, 29, 38, 33, 40, 39, 44, 45, 52, 49, 54, 53, 56, 57, 70, 61, 76, 63, 86, 65, 92, 71, 96, 77, 102, 79, 112, 81, 116, 83, 128, 95, 132, 97, 136, 103, 138, 113, 144, 119, 150, 121, 156, 125, 158, 135, 172, 139, 174, 143
Offset: 0
Keywords
Links
- N. J. A. Sloane, Table of n, a(n) for n = 0..30000 (updated Dec 18 2019; terms 0..2000 from T. D. Noe, terms 2001..10000 from Robert G. Wilson v)
- Romeo Meštrovic, On the distribution of primes in the alternating sums of consecutive primes, arXiv:1805.11657 [math.NT], 2018.
- Zhi-Wei Sun, On functions taking only prime values, J. Number Theory 133(2013), no.8, 2794-2812.
- Zhi-Wei Sun, On a sequence involving sums of primes, Bull. Aust. Math. Soc. 88(2013), 197-205.
Programs
-
Haskell
a008347 n = a008347_list !! n a008347_list = 0 : zipWith (-) a000040_list a008347_list -- Reinhard Zumkeller, Feb 09 2015
-
Magma
[0] cat [&+[ (-1)^k * NthPrime(n-k): k in [0..n-1]]: n in [1..70]]; // Vincenzo Librandi, May 26 2019
-
Maple
A008347 := proc(n) options remember; if n = 0 then 0 else abs(A008347(n-1)-ithprime(n)); fi; end;
-
Mathematica
Join[{0},Abs[Accumulate[Times@@@Partition[Riffle[Prime[Range[80]],{1,-1}], 2]]]] (* Harvey P. Dale, Dec 11 2011 *) f[n_] := Abs@ Sum[(-1)^k Prime[k], {k, n - 1}]; Array[f, 70] (* Robert G. Wilson v, Oct 08 2013 *) a[0] = 0; a[n_] := a[n] = Prime[n] - a[n - 1]; Array[a, 70, 0] (* Robert G. Wilson v, Oct 16 2013 *) FoldList[#2 - # &, 0, Array[Prime, 30]] (* Horst H. Manninger, Oct 29 2021 *)
-
PARI
a(n)=abs(sum(i=1,n,(-1)^i*prime(i))) \\ Charles R Greathouse IV, Apr 29 2015
-
Python
from sympy import nextprime p = a = 0; L = [a] for n in range(1, 67): p = nextprime(p); a = p - a; L.append(a) print(*L, sep = ", ") # Ya-Ping Lu, May 07 2023
Formula
a(n) = prime(n) - a(n-1) for n >= 1.
a(n+2) - a(n) = A001223(n+1). - Reinhard Zumkeller, Feb 09 2015
G.f: (x*b(x))/(1+x), where b(x) is the g.f. of A000040. - Mario C. Enriquez, Dec 10 2016
Meštrovic (2018), following Pillai, conjectures that
a(2k) = k*log k + k*loglog k - k + o(k) as k -> oo,
with a similar conjecture for a(2k+1). - N. J. A. Sloane, Dec 21 2019
Comments