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.

Showing 1-2 of 2 results.

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

Original entry on oeis.org

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
Offset: 0

Views

Author

Rémy Sigrist, Nov 23 2017

Keywords

Comments

a(n) = n iff n is prime.
For any n >= 0, a(n) <= A295335(n).
See A295335 for the OR variant.

Examples

			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.
		

Crossrefs

Cf. A295335.

Programs

  • 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 *)
  • 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

Formula

Empirically, for any k > 1, a(2*k+1) = a(2*k)-1.

A295609 a(n) = least prime number p such that p AND n = n (where AND denotes the binary AND operator).

Original entry on oeis.org

2, 3, 2, 3, 5, 5, 7, 7, 11, 11, 11, 11, 13, 13, 31, 31, 17, 17, 19, 19, 23, 23, 23, 23, 29, 29, 31, 31, 29, 29, 31, 31, 37, 37, 43, 43, 37, 37, 47, 47, 41, 41, 43, 43, 47, 47, 47, 47, 53, 53, 59, 59, 53, 53, 127, 127, 59, 59, 59, 59, 61, 61, 127, 127, 67, 67
Offset: 0

Views

Author

Rémy Sigrist, Nov 24 2017

Keywords

Comments

For any n > 0: gcd(A109613(n), A062383(n)) = 1, hence, by Dirichlet's theorem on arithmetic progressions, we have a prime number, say p, of the form A109613(n) + k * A062383(n) with k > 0; this prime number satisfies p AND n = n; also a(0) = 2, hence the sequence is well defined for any n >= 0.
a(n) = n iff n is prime.
Each prime number appears 2*k times in this sequence for some k > 0.

Examples

			a(42) = 42 + A295335(42) = 42 + 1 = 43.
		

Crossrefs

Programs

  • Mathematica
    Table[Block[{p = 2}, While[BitAnd[p, n] != n, p = NextPrime@ p]; p], {n, 0, 65}] (* Michael De Vlieger, Nov 26 2017 *)
  • PARI
    avoid(n,i) = if (i, if (n%2, 2*avoid(n\2,i), 2*avoid(n\2,i\2)+(i%2)), 0) \\ (i+1)-th number k such that k AND n = 0
    a(n) = for (i=0, oo, my (k=avoid(n,i)); if (isprime(n+k), return (n+k)))

Formula

a(n) = n + A295335(n).
For any k > 1, a(2*k) = a(2*k+1).
Showing 1-2 of 2 results.