A366094 Least prime nearest to the sum of the first n primes.
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
Examples
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.
Links
- Paolo Xausa, Table of n, a(n) for n = 0..10000
Programs
-
Mathematica
pNearest[n_]:=If[PrimeQ[n],n,With[{np=NextPrime[n],pp=NextPrime[n,-1]},If[np-n
A366094list[nmax_]:=Prepend[Map[pNearest,Accumulate[Prime[Range[nmax]]]],2]; A366094list[100] -
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