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 A117387 #18 Dec 13 2022 07:55:30 %S A117387 2,2,3,7,17,31,61,127,257,509,1021,2053,4093,8191,16381,32771,65537, %T A117387 131071,262147,524287,1048573,2097143,4194301,8388617,16777213, %U A117387 33554467,67108859,134217757,268435459,536870909,1073741827,2147483647,4294967291,8589934583 %N A117387 Prime nearest to 2^n. In case of a tie, choose the smaller. %H A117387 Harvey P. Dale, <a href="/A117387/b117387.txt">Table of n, a(n) for n = 0..1000</a> %F A117387 a(n) = A000079(n) - A059959(n). [Corrected by _Georg Fischer_, Dec 13 2022] %t A117387 f[n_] := Block[{k = 0}, While[ !PrimeQ[2^n - k] && !PrimeQ[2^n + k], k++ ]; Min@Select[{2^n - k, 2^n + k}, PrimeQ@# &]] %t A117387 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 *) %o A117387 (Python) %o A117387 from sympy import prevprime, nextprime %o A117387 def A117387(n): return (m if (m:=nextprime(k:=1<<n)) < (k<<1)-(r:=prevprime(k)) else r) if n>1 else 2 # _Chai Wah Wu_, Aug 08 2022 %K A117387 nonn %O A117387 0,1 %A A117387 _Lekraj Beedassy_, Mar 11 2006 %E A117387 Edited, corrected and extended by _Robert G. Wilson v_, Mar 14 2006