A335653 Smallest prime whose binary expansion has Hamming distance 1 from 2n+1, or 0 if no such prime exists.
3, 2, 7, 3, 11, 3, 5, 7, 19, 3, 5, 7, 17, 11, 13, 23, 37, 3, 5, 7, 43, 11, 13, 43, 17, 19, 37, 23, 41, 43, 29, 31, 67, 3, 5, 7, 89, 11, 13, 71, 17, 19, 1109, 23, 73, 83, 29, 31, 101, 67, 37, 71, 41, 43, 101, 47, 97, 83, 53, 103, 89, 59, 61, 383, 131, 3, 5, 7, 139, 11, 13, 139, 17, 19, 151, 23
Offset: 0
Examples
For n = 4, 2n+1 = 1001_2, and the smallest prime with Hamming distance 1 is 1011_2 = 11.
Links
- Robert Israel, Table of n, a(n) for n = 0..2234
- MathOverflow, Hamming Distance to Primes
Programs
-
Maple
f:= proc(n) local L, nL, k, v; L:= convert(n, base, 2); nL:= nops(L); for k from nL to 1 by -1 do if L[k] = 1 then v:= n - 2^(k-1); if isprime(v) then return v fi; fi od; for k from 1 to nL do if L[k] = 0 then v:= n + 2^(k-1); if isprime(v) then return v fi; fi od; for k from nL+1 do v:= n+2^(k-1); if isprime(v) then return v fi; od end proc: map(f, [seq(i, i=1..200, 2)]); # Robert Israel, Jun 15 2020
-
Mathematica
a[n_Integer] := a[IntegerDigits[2 n + 1, 2]]; a[bin_List] := Module[{flips, primes}, flips = Sort[FromDigits[bin, 2] + (1 - 2 bin) Power[2, Length[bin] - Range[Length[bin]]]]; primes = Select[flips, PrimeQ]; If[Length[primes] >= 1, First[primes], a[FromDigits[bin, 2], Length[bin]]] ]; a[n_Integer, k_Integer] := Module[{test = n + Power[2, k]}, test /; PrimeQ[test]]; a[n_Integer, k_Integer] := a[n, k + 1]; Table[a[n],{n,0,50}]
-
PARI
a(n) = my(p=2); while(norml2(binary(bitxor(p, 2*n+1))) != 1, p = nextprime(p+1)); p; \\ Michel Marcus, Jun 16 2020
Formula
a((p+2^k-1)/2) = p if p is an odd prime and 2^k > p-3. - Robert Israel, Jun 16 2020
Comments