%I #22 Feb 19 2024 10:27:31
%S 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,
%T 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,
%U 14,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,1
%N a(n) is the least nonnegative integer k such that n XOR k is a square (where XOR denotes the bitwise XOR operator).
%C This sequence has similarities with A329794 as the XOR operator and the "box" operator defined in A329794 both map (n, n) to 0 for any n (however here we accept 0 as a square).
%H Rémy Sigrist, <a href="/A330270/b330270.txt">Table of n, a(n) for n = 0..8192</a>
%H Rémy Sigrist, <a href="/A330270/a330270.png">Scatterplot of the ordinal transform of the first 2^20 terms</a>
%H Rémy Sigrist, <a href="/A330270/a330270_1.png">Scatterplot of (x, y) such that x XOR y is a square, 0 <= x, y <= 1023</a>
%F a(n) = 0 iff n is a square.
%F a(a(n)) <= n.
%e For n = 7,
%e - 7 XOR 0 = 7 (not a square),
%e - 7 XOR 1 = 6 (not a square),
%e - 7 XOR 2 = 5 (not a square),
%e - 7 XOR 3 = 4 = 2^2,
%e - hence a(7) = 3.
%t A330270[n_] := Module[{k = -1}, While[!IntegerQ[Sqrt[BitXor[n, ++k]]]]; k];
%t Array[A330270, 100, 0] (* _Paolo Xausa_, Feb 19 2024 *)
%o (PARI) a(n) = for (k=0, oo, if (issquare(bitxor(n, k)), return (k)))
%o (Python)
%o from itertools import count
%o from sympy.ntheory.primetest import is_square
%o def A330270(n): return next(k for k in count(0) if is_square(n^k)) # _Chai Wah Wu_, Aug 22 2023
%Y See A330271 for the cube variant.
%Y Cf. A000290, A003987, A295520, A329794.
%K nonn,base,easy
%O 0,3
%A _Rémy Sigrist_, Dec 08 2019
|