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

A366094
Least prime nearest to the sum of the first n primes.
3
2, 2, 5, 11, 17, 29, 41, 59, 79, 101, 127, 157, 197, 239, 281, 331, 379, 439, 499, 569, 641, 709, 787, 877, 967, 1061, 1163, 1259, 1373, 1481, 1597, 1721, 1847, 1987, 2129, 2273, 2423, 2579, 2749, 2917, 3089, 3271, 3449, 3637, 3833, 4027, 4229, 4441, 4663, 4889
OFFSET
0,1
EXAMPLE
a(3) = 11 because the sum of the first 3 primes is 2 + 3 + 5 = 10 and the nearest prime is 11.
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.
MATHEMATICA
pNearest[n_]:=If[PrimeQ[n], n, With[{np=NextPrime[n], pp=NextPrime[n, -1]}, If[np-n<n-pp, np, pp]]];
A366094list[nmax_]:=Prepend[Map[pNearest, Accumulate[Prime[Range[nmax]]]], 2];
A366094list[100]
PROG
(Python)
from sympy import prime, nextprime, prevprime
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
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Paolo Xausa, Sep 29 2023
STATUS
approved