cp's OEIS Frontend

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.

A117387 Prime nearest to 2^n. In case of a tie, choose the smaller.

Original entry on oeis.org

2, 2, 3, 7, 17, 31, 61, 127, 257, 509, 1021, 2053, 4093, 8191, 16381, 32771, 65537, 131071, 262147, 524287, 1048573, 2097143, 4194301, 8388617, 16777213, 33554467, 67108859, 134217757, 268435459, 536870909, 1073741827, 2147483647, 4294967291, 8589934583
Offset: 0

Views

Author

Lekraj Beedassy, Mar 11 2006

Keywords

Programs

  • Mathematica
    f[n_] := Block[{k = 0}, While[ !PrimeQ[2^n - k] && !PrimeQ[2^n + k], k++ ]; Min@Select[{2^n - k, 2^n + k}, PrimeQ@# &]]
    pn2n[n_]:=Module[{c=2^n,a,b},a=NextPrime[c,-1];b=NextPrime[c];If[b-c < c-a,b,a]]; Join[{2,2},Table[pn2n[n],{n,2,40}]] (* Harvey P. Dale, Jul 24 2019 *)
  • Python
    from sympy import prevprime, nextprime
    def A117387(n): return (m if (m:=nextprime(k:=1<1 else 2 # Chai Wah Wu, Aug 08 2022

Formula

a(n) = A000079(n) - A059959(n). [Corrected by Georg Fischer, Dec 13 2022]

Extensions

Edited, corrected and extended by Robert G. Wilson v, Mar 14 2006