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.

A295520 a(n) is the least k >= 0 such that n XOR k is prime (where XOR denotes the bitwise XOR operator).

This page as a plain text file.
%I A295520 #23 Aug 24 2023 02:42:40
%S A295520 2,2,0,0,1,0,1,0,3,2,1,0,1,0,3,2,1,0,1,0,3,2,1,0,5,4,5,4,1,0,1,0,5,4,
%T A295520 7,6,1,0,3,2,1,0,1,0,3,2,1,0,5,4,7,6,1,0,3,2,3,2,1,0,1,0,3,2,3,2,1,0,
%U A295520 3,2,1,0,1,0,3,2,3,2,1,0,3,2,1,0,7,6,5
%N A295520 a(n) is the least k >= 0 such that n XOR k is prime (where XOR denotes the bitwise XOR operator).
%C A295520 a(n) = n iff n is prime.
%C A295520 For any n >= 0, a(n) <= A295335(n).
%C A295520 See A295335 for the OR variant.
%H A295520 Robert Israel, <a href="/A295520/b295520.txt">Table of n, a(n) for n = 0..10000</a>
%H A295520 Rémy Sigrist, <a href="/A295520/a295520.png">Scatterplot of (x, y) such that x XOR y is prime and x, y < 1024</a>
%F A295520 Empirically, for any k > 1, a(2*k+1) = a(2*k)-1.
%e A295520 For n = 44:
%e A295520 - 44 XOR 0 = 44 is not prime,
%e A295520 - 44 XOR 1 = 45 is not prime,
%e A295520 - 44 XOR 2 = 46 is not prime,
%e A295520 - 44 XOR 3 = 47 is prime,
%e A295520 - hence a(44) = 3.
%p A295520 f:= proc(n) local k;
%p A295520   for k from 0 do if isprime(Bits:-Xor(k,n)) then return k fi od
%p A295520 end proc:
%p A295520 map(f, [$0..200]); # _Robert Israel_, Nov 27 2017
%t A295520 Table[Block[{k = 0}, While[! PrimeQ@ BitXor[k, n], k++]; k], {n, 0, 104}] (* _Michael De Vlieger_, Nov 26 2017 *)
%o A295520 (PARI) a(n) = for (k=0, oo, if (isprime(bitxor(n,k)), return (k)))
%o A295520 (Python)
%o A295520 from itertools import count
%o A295520 from sympy import isprime
%o A295520 def A295520(n): return next(k for k in count(0) if isprime(n^k)) # _Chai Wah Wu_, Aug 23 2023
%Y A295520 Cf. A295335.
%K A295520 nonn,base
%O A295520 0,1
%A A295520 _Rémy Sigrist_, Nov 23 2017