login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A013603
Difference between 2^n and the nearest prime less than or equal to 2^n.
31
0, 1, 1, 3, 1, 3, 1, 5, 3, 3, 9, 3, 1, 3, 19, 15, 1, 5, 1, 3, 9, 3, 15, 3, 39, 5, 39, 57, 3, 35, 1, 5, 9, 41, 31, 5, 25, 45, 7, 87, 21, 11, 57, 17, 55, 21, 115, 59, 81, 27, 129, 47, 111, 33, 55, 5, 13, 27, 55, 93, 1, 57, 25, 59, 49, 5, 19, 23, 19, 35, 231, 93, 69, 35, 97, 15
OFFSET
1,4
COMMENTS
If a(n) = 1, then n is prime and 2^n - 1 is a Mersenne prime. - Franz Vrabec, Sep 27 2005
Using the first variant A007917 (rather than A151799) of the prevprime() function, the sequence is well defined for n = 1, with a(1) = 2^1 - prevprime(2^1) = 2 - 2 = 0. - M. F. Hasler, Sep 09 2015
In Mathematica, one can use NextPrime with a second argument of -1 to obtain the next smaller prime. As almost all the powers of 2 are composite, this produces the proper results for most of this sequence. However, NextPrime[2, -1] returns -2 rather than the expected 2, which would consequently mean a(1) = 4 rather than 0. - Alonso del Arte, Dec 10 2016
LINKS
T. D. Noe, Table of n, a(n) for n = 1..5000 (corrected by Sean A. Irvine, Jan 18 2019)
V. Danilov, Table for large n.
FORMULA
a(n) = A049711(2^n). - R. J. Mathar, Nov 28 2016
a(n) = 2^n - prevprime(2^n) = 2^n - prime(primepi(2^n)). - Alonso del Arte, Dec 10 2016
MAPLE
seq(2^i-prevprime(2^i), i=2..100);
MATHEMATICA
{0} ~Join~ Array[With[{c = 2^#}, c - NextPrime[c, -1]] &, 80, 2] (* Harvey P. Dale, Jul 23 2013 *)
Table[2^n - Prime[PrimePi[2^n]], {n, 80}] (* Alonso del Arte, Dec 10 2016 *)
PROG
(PARI) a(n) = 2^n - precprime(2^n); \\ Michel Marcus, Apr 04 2020
CROSSREFS
Equivalent sequence for next prime: A092131.
Sequence in context: A309891 A317937 A322436 * A157892 A264441 A351566
KEYWORD
nonn
AUTHOR
James Kilfiger (mapdn(AT)csv.warwick.ac.uk)
EXTENSIONS
Extended to a(1) = 0 by M. F. Hasler, Sep 09 2015
STATUS
approved