A330270 a(n) is the least nonnegative integer k such that n XOR k is a square (where XOR denotes the bitwise XOR operator).
0, 0, 2, 2, 0, 1, 2, 3, 1, 0, 3, 2, 5, 4, 7, 6, 0, 1, 2, 3, 4, 5, 6, 7, 1, 0, 3, 2, 5, 4, 7, 6, 4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11, 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1
Offset: 0
Examples
For n = 7, - 7 XOR 0 = 7 (not a square), - 7 XOR 1 = 6 (not a square), - 7 XOR 2 = 5 (not a square), - 7 XOR 3 = 4 = 2^2, - hence a(7) = 3.
Links
- Rémy Sigrist, Table of n, a(n) for n = 0..8192
- Rémy Sigrist, Scatterplot of the ordinal transform of the first 2^20 terms
- Rémy Sigrist, Scatterplot of (x, y) such that x XOR y is a square, 0 <= x, y <= 1023
Programs
-
Mathematica
A330270[n_] := Module[{k = -1}, While[!IntegerQ[Sqrt[BitXor[n, ++k]]]]; k]; Array[A330270, 100, 0] (* Paolo Xausa, Feb 19 2024 *)
-
PARI
a(n) = for (k=0, oo, if (issquare(bitxor(n, k)), return (k)))
-
Python
from itertools import count from sympy.ntheory.primetest import is_square def A330270(n): return next(k for k in count(0) if is_square(n^k)) # Chai Wah Wu, Aug 22 2023
Formula
a(n) = 0 iff n is a square.
a(a(n)) <= n.
Comments