login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A295520 a(n) is the least k >= 0 such that n XOR k is prime (where XOR denotes the bitwise XOR operator). 5
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, 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, 3, 2, 1, 0, 1, 0, 3, 2, 3, 2, 1, 0, 3, 2, 1, 0, 7, 6, 5 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,1
COMMENTS
a(n) = n iff n is prime.
For any n >= 0, a(n) <= A295335(n).
See A295335 for the OR variant.
LINKS
FORMULA
Empirically, for any k > 1, a(2*k+1) = a(2*k)-1.
EXAMPLE
For n = 44:
- 44 XOR 0 = 44 is not prime,
- 44 XOR 1 = 45 is not prime,
- 44 XOR 2 = 46 is not prime,
- 44 XOR 3 = 47 is prime,
- hence a(44) = 3.
MAPLE
f:= proc(n) local k;
for k from 0 do if isprime(Bits:-Xor(k, n)) then return k fi od
end proc:
map(f, [$0..200]); # Robert Israel, Nov 27 2017
MATHEMATICA
Table[Block[{k = 0}, While[! PrimeQ@ BitXor[k, n], k++]; k], {n, 0, 104}] (* Michael De Vlieger, Nov 26 2017 *)
PROG
(PARI) a(n) = for (k=0, oo, if (isprime(bitxor(n, k)), return (k)))
(Python)
from itertools import count
from sympy import isprime
def A295520(n): return next(k for k in count(0) if isprime(n^k)) # Chai Wah Wu, Aug 23 2023
CROSSREFS
Cf. A295335.
Sequence in context: A297814 A298177 A298146 * A295335 A227838 A050605
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Nov 23 2017
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 23 20:33 EDT 2024. Contains 371916 sequences. (Running on oeis4.)