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”).

Least prime nearest to the sum of the first n primes.
3

%I #22 Oct 03 2023 10:34:13

%S 2,2,5,11,17,29,41,59,79,101,127,157,197,239,281,331,379,439,499,569,

%T 641,709,787,877,967,1061,1163,1259,1373,1481,1597,1721,1847,1987,

%U 2129,2273,2423,2579,2749,2917,3089,3271,3449,3637,3833,4027,4229,4441,4663,4889

%N Least prime nearest to the sum of the first n primes.

%H Paolo Xausa, <a href="/A366094/b366094.txt">Table of n, a(n) for n = 0..10000</a>

%e a(3) = 11 because the sum of the first 3 primes is 2 + 3 + 5 = 10 and the nearest prime is 11.

%e a(10) = 127 because the sum of the first 10 primes is 129, which is equidistant from the nearest primes (127 and 131), and 127 is the smaller one.

%t pNearest[n_]:=If[PrimeQ[n],n,With[{np=NextPrime[n],pp=NextPrime[n,-1]},If[np-n<n-pp,np,pp]]];

%t A366094list[nmax_]:=Prepend[Map[pNearest,Accumulate[Prime[Range[nmax]]]],2];

%t A366094list[100]

%o (Python)

%o from sympy import prime, nextprime, prevprime

%o def A366094(n): return (p if ((m:=sum(prime(i) for i in range(1,n+1)))<<1)-(p:=prevprime(m+1))<=(k:=nextprime(m)) else k) if n else 2 # _Chai Wah Wu_, Oct 03 2023

%Y Cf. A000040, A007504, A366092.

%Y Cf. A353295, A354329.

%K nonn,easy

%O 0,1

%A _Paolo Xausa_, Sep 29 2023