A374179
a(n) is the least prime p such that the binary expansions of p and of the next prime q > p differ at exactly n positions, and p and q have the same binary length.
Original entry on oeis.org
2, 11, 47, 139, 157, 191, 1151, 1531, 3067, 7159, 20479, 36857, 49139, 98299, 360439, 917503, 1310719, 786431, 6291449, 5242877, 20971507, 58720253, 83886053, 201326557, 335544301, 402653171, 3489660919, 1879048183, 5368709117, 25769803751, 21474836479, 77309411323
Offset: 1
a(n): 2 11 47 139 157
np 3 13 53 149 163
[1 0] [1 0 1 1] [1 0 1 1 1 1] [1 0 0 0 1 0 1 1] [1 0 0 1 1 1 0 1]
[1 1] [1 1 0 1] [1 1 0 1 0 1] [1 0 0 1 0 1 0 1] [1 0 1 0 0 0 1 1]
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
n: 1 2 3 4 5
-
from sympy import nextprime
def A374179(n):
p, pb = 2, 2
while (q:=nextprime(p)):
if pb==(qb:=q.bit_length()) and (p^q).bit_count() == n:
return p
p, pb = q, qb # Chai Wah Wu, Jul 10 2024
A374402
Least number that is the lesser of two consecutive primes p and q whose binary expansions have the same length and agree at exactly n digit positions, or -1 if no such prime pair exists.
Original entry on oeis.org
2, 5, 23, 17, 41, 67, 137, 269, 521, 1049, 2081, 4111, 8233, 16417, 32771, 65537, 131113, 262147, 524309, 1048609, 2097257, 4194389, 8388617, 16777289, 33554501, 67109123, 134217929, 268435459, 536871017, 1073741827, 2147484041, 4294967497, 8589934627, 17179869731
Offset: 1
a(1) = 2 because 2 = 10_2 and 3 = 11_2 are two consecutive primes that, when written in base 2, both have 2 digits and agree at exactly 1 digit position (each has a 1 in its first digit position), and no earlier pair of consecutive primes has this property.
a(3) = 23 = 10111_2; the next prime is
29 = 11101_2 (same number of binary digits),
^ ^ ^ and the digits agree at 3 digit positions,
and no earlier pair of consecutive primes has this property.
-
card(p)=my(u=binary(p),v=binary(nextprime(p+1))); if(#u!=#v,return(0)); sum(i=1,#u,u[i]==v[i])
a(n)=forprime(p=2^n,oo,if(card(p)==n,return(p)))