cp's OEIS Frontend

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.

A383271 Number of primes (excluding n) that may be generated by replacing any binary digit of n with a digit from 0 to 1.

This page as a plain text file.
%I A383271 #27 Apr 23 2025 19:31:05
%S A383271 0,0,1,1,1,1,2,2,0,2,2,1,1,1,0,3,1,1,2,3,0,4,1,3,0,2,0,3,1,2,1,2,0,2,
%T A383271 1,2,1,2,0,3,1,1,1,4,0,5,1,1,0,2,0,2,1,2,0,2,0,3,1,1,1,2,0,4,0,3,2,3,
%U A383271 0,3,1,4,1,1,0,5,0,4,1,1,0,4,1,2,0,0,0,3,1,1
%N A383271 Number of primes (excluding n) that may be generated by replacing any binary digit of n with a digit from 0 to 1.
%C A383271 Also, the number of prime neighbors of n in H(A070939(n), 2), where H(k, b) is the Hamming graph whose vertices are the sequences of length k over the alphabet {0,1,...,b-1} with adjacency being defined by having Hamming distance 1 (see A145667).
%C A383271 Prepending 1 is not allowed.
%H A383271 Michael S. Branicky, <a href="/A383271/b383271.txt">Table of n, a(n) for n = 0..10000</a>
%e A383271 a(3) = 1 since 3 = 11_2 can be changed to 10_2 = 2, which is prime.
%e A383271 a(5) = 1 since 5 = 101_2 can be changed to 001_2 = 1, 111_2 = 7 (prime), or 100_2 = 4.
%e A383271 a(6) = 2 since 6 = 110_2 can be changed to 010_2 = 2 (prime), 100_2 = 4, or 111_2 = 7 (prime).
%e A383271 a(7) = 2 since 7 = 111_2 can be changed to 011_2 = 3 (prime), 101_2 = 5 (prime), or 110_2 = 6.
%p A383271 a:= n-> nops(select(isprime, [seq(Bits[Xor](2^i, n), i=0..ilog2(n))])):
%p A383271 seq(a(n), n=0..100);  # _Alois P. Heinz_, Apr 23 2025
%t A383271 A383271[n_] := Count[BitXor[n, 2^Range[0, BitLength[n] - 1]], _?PrimeQ];
%t A383271 Array[A383271, 100, 0] (* _Paolo Xausa_, Apr 23 2025 *)
%o A383271 (Python)
%o A383271 from gmpy2 import is_prime
%o A383271 def a(n):
%o A383271     if n == 0:
%o A383271         return 0
%o A383271     if n&1 == 0:
%o A383271         return int(is_prime(n + 1)) + int(1<<(n.bit_length()-1)^n == 2)
%o A383271     mask, c = 1, 0
%o A383271     for i in range(n.bit_length()):
%o A383271         if is_prime(mask^n):
%o A383271             c += 1
%o A383271         mask <<= 1
%o A383271     return c
%o A383271 print([a(n) for n in range(90)])
%Y A383271 Base-2 analog of A209252.
%Y A383271 Cf. A070939, A145667, A352942.
%K A383271 nonn,base
%O A383271 0,7
%A A383271 _Michael S. Branicky_, Apr 21 2025