cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

User: R. J. Cano

R. J. Cano's wiki page.

R. J. Cano has authored 19 sequences. Here are the ten most recent ones:

A306520 Numbers k with property that the arithmetic mean of any subset of its digits is an integer.

Original entry on oeis.org

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 17, 19, 20, 22, 24, 26, 28, 31, 33, 35, 37, 39, 40, 42, 44, 46, 48, 51, 53, 55, 57, 59, 60, 62, 64, 66, 68, 71, 73, 75, 77, 79, 80, 82, 84, 86, 88, 91, 93, 95, 97, 99, 111, 117, 135, 153, 159, 171, 177, 195
Offset: 1

Author

R. J. Cano, Feb 21 2019

Keywords

Comments

This sequence is different from A061383. Here digits in k must have all the same parity, otherwise the average of at least a pair of digits wouldn't be an integer. Note that for every 2-digit term in A061383 both digits have the same parity. But not every number whose digits have all the same parity (sequence A059708) belongs here.

Examples

			17 is in this sequence because the set of digits (1,7) has an integer average: 4.
159 and 195 are in this sequence because the sets of digits (1,5), (1,9), (5,9), and (1,5,9) all have integer averages, respectively: 3, 5, 7, and 5.
		

Crossrefs

Programs

  • Mathematica
    Select[Range[0,200],AllTrue[Mean/@Subsets[IntegerDigits[#],{2, IntegerLength[ #]}],IntegerQ]&] (* Requires Mathematica version 10 or later *) (* Harvey P. Dale, Aug 09 2020 *)
  • PARI
    firstTerms_vec(n)={my(v=vector(n),c,t,w:list,h);for(i=1,+oo,w=List();forsubset(i,k,listput(w,k));listpop(w,1);forvec(j=vector(i,z,[(z==1)&&(i>1),9]),h=j[1]%2;for(l=2,#j,if((j[l]%2)!=h,next(2)));for(k=1,#w,t=vecextract(j,w[k]);if(vecsum(t)%(#w[k]),next(2)));v[c++]=fromdigits(j);if(c==n,return(v))))}
    
  • PARI
    isok(m,{B=10})={my(w=digits(m,B));forsubset(#w,y,if(y!=Vecsmall([]),if(vecsum(vecextract(w,y))%(#y),return(0)),next));1}

Formula

Apparently a(158+n) = A010785(35+n).

A302692 Primes p that are the sum of another prime q and the greatest k such that k! < p.

Original entry on oeis.org

5, 41, 47, 71, 83, 101, 107, 113, 733, 739, 757, 827, 829, 859, 863, 883, 887, 947, 953, 977, 983, 997, 1019, 1039, 1069, 1093, 1097, 1103, 1109, 1123, 1129, 1187, 1193, 1223, 1229, 1237, 1283, 1289, 1297, 1303, 1307, 1327, 1367, 1373, 1429, 1433, 1439, 1453, 1459
Offset: 1

Author

R. J. Cano, Apr 08 2018

Keywords

Comments

Primes p such that p - A084558(p) is also a prime.
Inspired by the fact that this sequence has a nonempty intersection with A124598.
Let H be the intersection of this sequence and A124598. With some observed exceptions q = 3, 103, 1013, 1223, 2903, ..., if some p in this sequence is in H then the corresponding q also belongs to H. It is unknown whether H is finite.
Based upon the first terms of this sequence, it looks like those k satisfying the definition given in NAME are the even terms of A084558 repeated in certain weakly increasing sequence.

Examples

			a(3) = 41 since 41 is the third prime that satisfies the given definition(s) for this sequence. Note that A084558(41) = 4; if we subtract: 41-4 = 37, which is also a prime. Also p = 41 and q = 37 are consecutive terms in A124598.
a(300) = 49459, because q = 49459 - A084558(49459) = 49451 is a prime and p = 49459 is the 300th prime satisfying such property. Also p and q are consecutive terms in A124598.
		

Crossrefs

Programs

  • Maple
    k:= 0: f:= 1: p:= 1: Res:= NULL: count:= 0:
    while count < 100 do
      p:= nextprime(p);
      while p > f do k:= k+1; f:= f*(k+1) od;
      if isprime(p-k) then Res:= Res, p; count:= count+1 fi;
    od:
    Res; # Robert Israel, Jun 10 2018
  • Mathematica
    Select[Prime@ Range[2^8], PrimeQ[# - Block[{k = 1}, While[k! <= #, k++]; k - 1]] &] (* Michael De Vlieger, Apr 10 2018 *)
  • PARI
    A084558(n)={my(m=0);while(n\=m++,);m-1}
    firstTerms(U)={my(L:list=List());forprime(p=2,nextprime(U),if(ispseudoprime(p-A084558(p)),listput(L,p)));return(Vec(L))}

A300326 Sum of the largest possible permutations that can be written without repetition of digits in each base from binary to n+1.

Original entry on oeis.org

0, 2, 23, 251, 3181, 47971, 848638, 17283462, 398650506, 10275193716, 292733747621, 9135147415313, 309906954656231, 11356162260536389, 447015900139452604, 18811774444632517324, 842820629057975778516, 40053081963609542635686, 2012366504118798707101875
Offset: 0

Author

R. J. Cano, Mar 03 2018

Keywords

Comments

It is seems that {a(1), a(2), a(3), a(4)} are the only primes of this form.
From M. F. Hasler, Mar 04 2018: (Start)
For p = 2 and p = 3, a(n) (mod p) is 8- resp. 9-periodic.
For primes 5 <= p <= 23, a(n) (mod p) is p(p-1) periodic. I conjecture this to hold for all p >= 5.
It also appears that the last 4 terms of these periods are (1, 1, 0, 0) (mod p), for any p >= 2, i.e., a(n) is divisible by p at least for k*P-2 <= n <= k*P for any k >= 0, where P is the period length p(p-1) (resp. 8 or 9 for p = 2 and 3).
These properties might allow a proof that a(1..4) are the only primes. However, a(12) = 14231491*21776141, so there is little hope of finding a reasonably sized finite covering set.
(End)

Examples

			Let us consider the numbers: 0[1], 10[2], 210[3], 3210[4], 43210[5], and 543210[6];
Their respective decimal representations are the first six terms of A062813: 0, 2, 21, 228, 2930, 44790. The partial sums for those terms are 0, 2, 23, 251, 3181, and 47971; after 0, the following 4 sums are primes, but 47971 is not prime. The same is true for subsequent partial sums, whence the conjecture in COMMENTS.
		

Crossrefs

Partial sums of A062813.
Cf. A233783 for the occurrence of the ordered triple (2,23,251) in a different context.

Programs

Extensions

Partially edited by M. F. Hasler, Mar 05 2018

A278930 a(n) is the least positive integer that differs (in absolute value) by an (n+1)-st power from the reverse of its binary representation.

Original entry on oeis.org

2, 36, 100, 2081, 8257, 32897, 131329, 524801, 2098177, 8390657, 33558529, 134225921, 536887297, 2147516417, 8590000129, 34359869441, 137439215617, 549756338177, 2199024304129, 8796095119361, 35184376283137, 140737496743937, 562949970198529, 2251799847239681
Offset: 1

Author

R. J. Cano, Dec 01 2016

Keywords

Comments

The numbers whose binary representation is a palindrome are excluded by definition because 0 is not a power of a positive number.
It might be thought that the first term should be 1 instead of 2, since by prepending its binary representation (itself) with a zero we get 01 with reverse 10 (decimal 2), and their difference in absolute value is abs(1-2)=1, which is itself its 1st power 1^1. However, leading zeros are ignored. Another alternative interpretation is to consider 1 as a palindrome, which also excludes it from this sequence.

Examples

			2 in binary is 10, its binary reverse 01 or simply 1 is the decimal number 1, subtracting them gives abs(2-1)=1, and since 1 is its own square, a(1)=2.
36 in binary is 100100, its binary reverse 1001 is the decimal number 9, subtracting them abs(36-9)=27=3^3, a third power, therefore a(2)=36.
100 in binary is 1100100, its binary reverse 10011 is the decimal number 19, subtracting them abs(100-19)=81=3^4, a fourth power, therefore a(3)=100.
For n>3 if we represent zeros with dots and place the binary representation for each term followed by its reverse, up to n=12 we obtain the graph:
1.....1....1
1....1.....1,
1......1.....1
1.....1......1,
1.......1......1
1......1.......1,
1........1.......1
1.......1........1,
1.........1........1
1........1.........1,
1..........1.........1
1.........1..........1,
1...........1..........1
1..........1...........1,
1............1...........1
1...........1............1,
1.............1............1
1............1.............1;
which illustrates better why the absolute value should be part of the definition, and how the difference is an (n+1)th power: From the first two rows for a(4) we have abs(2081-2113) = abs(-32) = 2^5.
		

Crossrefs

Inspired by: A278328.
Cf. A283050.

Programs

  • Mathematica
    Rest@ CoefficientList[Series[x (2 + 22 x - 124 x^2 + 1869 x^3 - 5198 x^4 + 3432 x^5)/((1 - x) (1 - 2 x) (1 - 4 x)), {x, 0, 24}], x] (* Michael De Vlieger, Dec 07 2016 *)
    LinearRecurrence[{7,-14,8},{2,36,100,2081,8257,32897},30]
  • PARI
    a(n)=if(n>3,1+2*(2^n+4^(n+1)),[2,36,100][n]);
    
  • PARI
    Vec(x*(2 + 22*x - 124*x^2 + 1869*x^3 - 5198*x^4 + 3432*x^5) / ((1 - x)*(1 - 2*x)*(1 - 4*x)) + O(x^30)) \\ Colin Barker, Dec 02 2016

Formula

For n>3, a(n) = 1+2*(2^n+4^(n+1)).
From Colin Barker, Dec 02 2016: (Start)
a(n) = 7*a(n-1) - 14*a(n-2) + 8*a(n-3) for n>6.
G.f.: x*(2 + 22*x - 124*x^2 + 1869*x^3 - 5198*x^4 + 3432*x^5) / ((1 - x)*(1 - 2*x)*(1 - 4*x)).
(End)

Extensions

More terms from Colin Barker, Dec 02 2016

A262016 a(n) = ( ( Sum_{k=1..n} 2^(prime(k)-1) ) mod n! ) / 2.

Original entry on oeis.org

0, 0, 2, 7, 15, 83, 91, 5163, 86315, 401323, 14725035, 65973803, 2562459691, 37695987243, 45627576875, 9183900142123, 39579412285995, 2598666482813483, 28017829467228715, 223446104928848427, 275288604322335275, 116723151945719253547, 12606804937123633465899
Offset: 1

Author

R. J. Cano and M. F. Hasler, Sep 08 2015

Keywords

Comments

This sequence appears to be dense in semiprimes.

Programs

  • Magma
    [(&+[2^(NthPrime(k)-1): k in [1..n]] mod Factorial(n))/2: n in [1..25]]; // Bruno Berselli, Sep 24 2015
  • Mathematica
    Table[Mod[Sum[2^(Prime[k] - 1), {k, n}], n!]/2, {n, 23}] (* Michael De Vlieger, Sep 09 2015 *)
  • PARI
    a(n)=sum(k=1,n,2^(prime(k)-1))%n!/2
    for(i=1,30,print1(a(i), ", ")); \\ R. J. Cano, Sep 08 2015
    

A245014 Least prime p such that 2n*4^n divides p + 4n^2 + 1.

Original entry on oeis.org

3, 47, 347, 6079, 10139, 147311, 687931, 18874111, 37748411, 104857199, 276823579, 805305791, 29662117211, 30064770287, 64424508539, 2473901161471, 11098195491707, 7421703486191, 83562883709531, 527765581330879, 369435906930971, 27866022694353007, 19421773393033147
Offset: 1

Author

R. J. Cano Sep 17 2014

Keywords

Comments

All those terms such that 2n*4^n is equal to p + 4n^2 + 1 belong to A247024.

Crossrefs

Cf. A247024.

Programs

  • Mathematica
    a[n_] := With[{k = n*2^(2*n+1)}, p = -4*n^2-1; While[!PrimeQ[p += k]]; p]; Table[a[n], {n, 1, 23}] (* Jean-François Alcover, Oct 09 2014, translated from Charles R Greathouse IV's PARI code *)
  • PARI
    search(u)={ /* Slow, u must be a small integer. */
      my(log2=log(2),q,t,t0,L1=List());
      forprime(y=3,prime(10^u),
        t=log(y+1)\log2;
        while(t>t0,
          q=4*t^2+y+1;
          if(q%(t*(2^(2*t+1)))==0,
            listput(L1,[t,y]);
            t0=t;
            break
          ,
            t--
          )));
      L1
    }
    
  • PARI
    a(n)=my(k=n<<(2*n+1),p=-4*n^2-1); while(!isprime(p+=k),); p \\ Charles R Greathouse IV, Sep 18 2014

Formula

a(n) << n^5*1024^n by Xylouris' version of Linnik's theorem. - Charles R Greathouse IV, Sep 18 2014

Extensions

a(10)-a(23) from Charles R Greathouse IV, Sep 18 2014

A247024 Primes of the form x*(2^x - x) - 1.

Original entry on oeis.org

3, 47, 347, 10139, 396527668833598369303619003, 1624796301562061610805093487, 2637188343637273091841153207596203623407
Offset: 1

Author

R. J. Cano, Sep 09 2014

Keywords

Comments

Subsequence of A245014. a(n) represents the identity between (p + 4k^2 + 1) and (2n*4^k) for the least prime p defining A245014(k). Those first k where it occurs are: 1,2,3,5,41,42,62,183,357,407.
Consider the table of Stirling numbers of the second kind (A008277). The second column contains the numbers A000225, or 2^m - 1, and the first subdiagonal contains the triangular numbers. If a number appears in both sequences, we have the equation f(x) = 2^x - x^2 + x - 2 = 0 which has integer roots x = 1, 2, 3. Set g(x) = (x - 1)*(2^x - 1). Then it is found that the sum f(x) + g(x) for some even x defines this sequence and satisfies in common with A245014: Both sequences have three consecutive terms (those first) such that when they are represented in decimal the third term is the concatenation of the two terms preceding it.
Prime or PRP for x = 2, 4, 6, 10, 82, 84, 124, 366, 714, 814, 1584, 8938, 17812, 27054, 35380, 71358. - Jens Kruse Andersen, Sep 10 2014
The complete solution to the remark on Stirling2 numbers in a comment above is given in A076046. See also my Oct 08 2014 remark in the history. - Wolfdieter Lang, Oct 16 2014

Crossrefs

Programs

  • Magma
    [a: x in [0..450] | IsPrime(a) where a is x*(2^x - x)-1]; // Vincenzo Librandi, Oct 16 2014
  • Maple
    A247024:=n->`if`(isprime(n*(2^n-n)-1),n*(2^n-n)-1,NULL): seq(A247024(n), n=1..10^2); # Wesley Ivan Hurt, Sep 13 2014
  • Mathematica
    Select[Table[n(2^n - n) - 1, {n, 200}], PrimeQ] (* Alonso del Arte, Sep 09 2014 *)
  • PARI
    listToVec(l:list,Comp,Omega=#l)=vector(Omega,i,l[i][Comp]);
    fplusg(x)=x*(2^x-x)-1;
    find_next_N_terms(N,resumeFrom:list=List(),verbose=0)= {
      my(s:list,q,j,F,N0);
      s=resumeFrom;
      q=#s;
      N0=q;
      if(q,j=s[q][1]);
      while(q
    				
  • PFGW
    ABC2 $a*(2^$a-$a)-1
    a: from 2 to 100000 step 2
    Charles R Greathouse IV, Sep 18 2014
    

Extensions

Edited: 'penultimate column' replaced by 'first subdiagonal'. - Wolfdieter Lang, Oct 16 2014

A243106 a(n) = Sum_{k=1..n} (-1)^isprime(k)*10^k.

Original entry on oeis.org

10, -90, -1090, 8910, -91090, 908910, -9091090, 90908910, 1090908910, 11090908910, -88909091090, 911090908910, -9088909091090, 90911090908910, 1090911090908910, 11090911090908910, -88909088909091090, 911090911090908910, -9088909088909091090
Offset: 1

Author

R. J. Cano, Aug 19 2014

Keywords

Comments

Alternative definition: a(n,x)=T(x,1) for a dichromate or Tutte-Whitney polynomial in which the matrix t[i,j] is defined as t[i,j]=Delta(i,j)*((-1)^isprime(i)) and "Delta" is the Kronecker Delta function. - Michel Marcus, Aug 19 2014
If 10 is replaced by 1, then this becomes A097454. If it is replaced by 2, one gets A242002. Choosing powers of the base b=10, as done here, allows one to easily read off the equivalent for any other base b > 4, by simply replacing digits 8,9 with b-2,b-1 (when terms are written in base b). [Comment extended by M. F. Hasler, Aug 20 2014]
There are 2^n ways of taking the partial sum of the first n powers of b=10 if exponent zero is excluded and the signs can be assigned arbitrarily. Conjecture: When expressed in base b, the absolute value for any of these terms only contains digits belonging to {0,1,b-2,b-1}; here {0,1,8,9}.

Examples

			n=1 is not prime x^1 = (10)^1 = 10, therefore a(1)=10;
n=2 is prime and x^2 = (10)^2 = 100, taking it negative, a(2) = 10 - 100 = -90;
n=3 also is prime, x^3 = 1000, and we have a(3) = 10 - 100 - 1000 = -1090;
n=4 is not prime, so a(4) = 10 - 100 - 1000 + 10000 = 8910;
n=5 is prime, then a(5) = 10 - 100 - 1000 + 10000 - 100000 = -91090;
Examples of analysis for the concatenation patterns among the terms can be found at the "Additional Information" link.
		

Crossrefs

Cf. A097454.
The same kind of base-independent behavior: A215940, A217626.
Partial sums of alternating series: A181482, A222739, A213203.

Programs

  • Mathematica
    Table[Sum[ (-1)^Boole@ PrimeQ@ k*10^k, {k, n}], {n, 19}] (* Michael De Vlieger, Jan 03 2016 *)
  • PARI
    ap(n, x)={my(s); forprime(p=1, n, s+=x^p); s}
    a=(n, x=10)->(x^(n+1)-1)/(x-1)-2*ap(n, x)-1;
    
  • PARI
    Delta=(i, j)->(i==j); /* Kronecker's Delta function */
    t=n->matrix(n, n, i, j, Delta(i, j)*((-1)^isprime(i))); /* coeffs t[i, j] */
    /* Tutte polynomial over n */
    T(n, x, y)={my(t0=t(n)); sum(i=1, n, sum(j=1, n, t0[i, j]*(x^i)*(y^j)))};
    a=(n, x=10)->T(n, x, 1);
    
  • PARI
    A243106(n,b=10)=sum(k=1,n,(-1)^isprime(k)*b^k) \\ M. F. Hasler, Aug 20 2014

Formula

a(n,x) = Sum_{k=1..n} (-1)^isprime(k)*(x^k), for x=10 in decimal.

Extensions

Definition simplified by N. J. A. Sloane, Aug 19 2014
Definition further simplified and more terms from M. F. Hasler, Aug 20 2014

A237265 Irregular table: n X n matrices (n=1,2,3,...), read by rows filled with numbers 1..n, with k moved to the front in the k-th row.

Original entry on oeis.org

1, 1, 2, 2, 1, 1, 2, 3, 2, 1, 3, 3, 1, 2, 1, 2, 3, 4, 2, 1, 3, 4, 3, 1, 2, 4, 4, 1, 2, 3, 1, 2, 3, 4, 5, 2, 1, 3, 4, 5, 3, 1, 2, 4, 5, 4, 1, 2, 3, 5, 5, 1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 2, 1, 3, 4, 5, 6, 3, 1, 2, 4, 5, 6, 4, 1, 2, 3, 5, 6, 5, 1, 2, 3, 4, 6, 6, 1, 2, 3, 4, 5
Offset: 1

Author

R. J. Cano, Feb 09 2014

Keywords

Comments

Cases of enumeration in ascending order for the first m positive integers when one of them, j, is previously excluded (m=1,2,3,..., 1 <= j <= m).
Table of the k initial permutations, one per block, when all the k! permutations in lexicographic ascending order are split uniformly into k blocks. Such table read by rows for k=1,2,3,... .
These permutations might be considered the initial inputs for a parallel/distributed variant of the Narayana Pandita's algorithm. Such variant would deliver to each thread/core/host one or more of the mentioned inputs, then the remaining permutations can be obtained with (k-1)!-1 executions of the classic Narayana Pandita's algorithm for the next permutation in lexical order.
The terms of A237450 give the positions of rows of this table among the rows of A030298. The finite n X n square matrices converge towards the infinite square array A237447. Please see further comments there. - Antti Karttunen, Feb 10 2014
Alternative way to express this is that each row k=1..n of each n X n matrix contains the lexicographically earliest n-letter permutation beginning with number k, or equally, that each of the n X n square matrices contain in their n rows those n-letter permutations of the symmetric group S_n that correspond to the inverses of cycles (1), (1 2), (1 2 3), ..., (1 2 ... n). Please see the Example section. - Antti Karttunen, Feb 12 2014

Examples

			By excluding 2, the natural numbers between 1 and 4 are 1,3,4, then the second row of the corresponding matrix must be [2,1,3,4] and a(22)=4; that is, when reading by rows, a(22) must be placed at the 4th matrix since 22 is greater than the sum of elements there in the preceding matrices and it is smaller than the next of such sums: 14 = (1 + 2^2 + 3^2) <= (22) <= (1 + 2^2 + 3^2 + 4^2) = 30. Therefore 14 is subtracted from 22 leaving 8. This means that a(22) is the 8th element in the fourth matrix read by rows, so a(22) = A(4)[2,4] (see formula).
The irregular table starts consists of successively larger squares (beginning with a 1 X 1 square {1}), where each larger (n+1) X (n+1) square contains the previous n X n square in its upper left corner, with the first n rows followed by n+1, and the last row consisting of (n+1) followed by the first row of the previous n X n square (i.e., terms 1, 2, ..., n):
Permutation  In cycle notation.  Inverse in cycle notation
1;           ( )                 ( )    [Note: ( ) stands for identity]
1,2;         ( )                 ( )
2,1;         (1 2)               (1 2)
1,2,3;       ( )                 ( )
2,1,3;       (1 2)               (1 2)
3,1,2;       (1 3 2)             (1 2 3)
1,2,3,4;     ( )                 ( )
2,1,3,4;     (1 2)               (1 2)
3,1,2,4;     (1 3 2)             (1 2 3)
4,1,2,3;     (1 4 3 2)           (1 2 3 4)
1,2,3,4,5;   ( )                 ( )
2,1,3,4,5;   (1 2)               (1 2)
3,1,2,4,5;   (1 3 2)             (1 2 3)
4,1,2,3,5;   (1 4 3 2)           (1 2 3 4)
5,1,2,3,4;   (1 5 4 3 2)         (1 2 3 4 5)
...
The table starts with 1 since the definition must be read in the mathematical sense of its statement. If we have N elements and one of them must be excluded, there are no elements available to exclude when N=1.
		

References

  • Donald Knuth, The Art of Computer Programming, Volume 4: "Generating All Tuples and Permutations" Fascicle 2, first printing. Addison-Wesley, 2005. ISBN 0-201-85393-0.

Programs

Formula

a(n) = A237447(1 + ((1/2) * ((col+row)^2 + col + 3*row)))[where col = A237451(n) and row = A237452(n)] = A237447bi(A237452(n),A237451(n)) [where A237447bi(row,col) is square array A237447 considered as a bivariate function]. - Antti Karttunen, Feb 10-12 2014

Extensions

Name changed and more terms added by Antti Karttunen, Feb 10 2014
Further edits by M. F. Hasler, Mar 09 2014

A235431 The smallest positive number that must be added to or subtracted from the sum of the first n primes in order to get a prime.

Original entry on oeis.org

1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 1, 2, 3, 4, 3, 4, 1, 2, 5, 2, 1, 4, 1, 4, 1, 2, 3, 4, 5, 2, 3, 2, 5, 2, 1, 2, 1, 2, 3, 2, 1, 2, 1, 2, 3, 2, 1, 2, 1, 10, 1, 4, 11, 2, 1, 6
Offset: 1

Author

R. J. Cano, Jan 17 2014

Keywords

Comments

The primes in A013918 would have associated a(n)=0 if not for the qualifier "positive" in the definition.
The sum of the first n primes appears to be close to a prime. For illustration, the maximum for a(n) among the first 5 million terms is a(808500) = 218.
See A013916 for the above mentioned indices, numbers n such that the sum of the first n primes is prime. - M. F. Hasler, Jan 20 2014

Examples

			The sum of the first 9 primes is 100, and by adding 1 we get 101. Since 101 is a prime, a(9) = 1.
The sum of the first 10 primes is 129, since 129 - 2 = prime(31) = 127 or 129 + 2 = prime(32) = 131, a(10) = 2.
The sum of the first 129 primes minus 1 is a prime, this is 42468 - 1 = prime(4443), so a(129) = 1.
		

Crossrefs

Programs

  • PARI
    a(n)=my(u=sum(j=1,n,prime(j)),k=1);while(!(isprime(u+k)||isprime(u-k)),k++);k

Formula

Algorithm:
Let S be the sum of the first n primes;
initially, let k=1;
increment k while neither S-k nor S+k is prime;
return a(n)=k.
a(n) = min(A013632(A007504(n)), A049711(A007504(n))). - M. F. Hasler, Jan 20 2014