OFFSET
0,1
LINKS
Paolo Xausa, Table of n, a(n) for n = 0..10000
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