VOOZH about

URL: https://oeis.org/A387053

⇱ A387053 - OEIS


login
A387053
a(n) is the least k such that n is the sum of a prime and k powers of 2.
1
0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 2, 0, 1, 0, 1, 1, 2, 0, 1, 1, 2, 1, 2, 0, 1, 0, 1, 1, 1, 1, 2, 0, 1, 1, 2, 0, 1, 0, 1, 1, 2, 0, 1, 1, 2, 1, 2, 0, 1, 1, 2, 1, 2, 0, 1, 0, 1, 1, 2, 1, 1, 0, 1, 1, 2, 0, 1, 0, 1, 1, 2, 1, 2, 0, 1, 1, 2, 0, 1, 1, 2, 1, 2, 0, 1, 1, 2, 1, 2, 1, 2, 0
OFFSET
2,15
LINKS
Thomas Bloom, Problem 10, Erdős Problems.
FORMULA
a(n) = 0 <=> n is prime.
EXAMPLE
a(4) = 1 as 4 is the sum of a prime (2) and one power of 2 (2) but 4 is not prime.
MATHEMATICA
a[n_]:=Module[{res}, If[PrimeQ[n], Return[0]]; res=Min[Map[DigitCount[n - #, 2, 1]&, Select[Range[2, n], PrimeQ]]]; res]; Array[a, 96, 2] (* James C. McMahon, Sep 23 2025 *)
PROG
(PARI) a(n) = if(isprime(n), return(0)); my(res=oo); forprime(p=2, n, res = min(res, hammingweight(n-p))); res
(Python)
from sympy import isprime, primerange
def a(n): return 0 if isprime(n) else min((n-p).bit_count() for p in primerange(1, n))
print([a(n) for n in range(2, 98)]) # Michael S. Branicky, Sep 20 2025
CROSSREFS
Cf. A000040.
Sequence in context: A342656 A293896 A066416 * A292342 A091991 A108234
KEYWORD
nonn
AUTHOR
David A. Corneth, Sep 20 2025
STATUS
approved