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.
%I A051701 #26 Jul 02 2025 16:01:58 %S A051701 3,2,3,5,13,11,19,17,19,31,29,41,43,41,43,47,61,59,71,73,71,83,79,83, %T A051701 101,103,101,109,107,109,131,127,139,137,151,149,151,167,163,167,181, %U A051701 179,193,191,199,197,199,227,229,227,229,241,239,257,251,257,271,269 %N A051701 Closest prime to n-th prime p that is different from p (break ties by taking the smaller prime). %C A051701 A227878 gives the terms occurring twice. - _Reinhard Zumkeller_, Oct 25 2013 %H A051701 T. D. Noe, <a href="/A051701/b051701.txt">Table of n, a(n) for n = 1..1000</a> %e A051701 Closest primes to 2,3,5,7,11 are 3,2,3,5,13. %t A051701 a[n_] := (p = Prime[n]; np = NextPrime[p]; pp = NextPrime[p, -1]; If[np-p < p-pp, np, pp]); Table[a[n], {n, 1, 58}] (* _Jean-François Alcover_, Oct 20 2011 *) %t A051701 cp[{a_,b_,c_}]:=If[c-b<b-a,c,a]; Join[{3},cp/@Partition[Prime[Range[ 60]],3,1]] (* _Harvey P. Dale_, Oct 08 2012 *) %o A051701 (Haskell) %o A051701 a051701 n = a051701_list !! (n-1) %o A051701 a051701_list = f 2 $ 1 : a000040_list where %o A051701 f d (q:ps@(p:p':_)) = (if d <= d' then q else p') : f d' ps %o A051701 where d' = p' - p %o A051701 -- _Reinhard Zumkeller_, Oct 25 2013 %o A051701 (Python) %o A051701 from sympy import nextprime %o A051701 def aupton(terms): %o A051701 prv, cur, nxt, alst = 0, 2, 3, [] %o A051701 while len(alst) < terms: %o A051701 alst.append(prv if 2*cur - prv <= nxt else nxt) %o A051701 prv, cur, nxt = cur, nxt, nextprime(nxt) %o A051701 return alst %o A051701 print(aupton(58)) # _Michael S. Branicky_, Jun 04 2021 %Y A051701 Related sequences: A023186, A023187, A023188, A046929, A046930, A046931, A051650, A051652, A051697, A051698, A051699, A051700, A051701, A051702, A051728, A051729, A051730. %Y A051701 Cf. A116946 (semiprime analog). %K A051701 nonn,easy,nice %O A051701 1,1 %A A051701 _N. J. A. Sloane_ %E A051701 More terms from _James Sellers_