OFFSET
1,1
COMMENTS
Numbers x such that both x and x^2 are terms of A031443, that is, have the same number of 0's as 1's in their binary representations.
MATHEMATICA
balQ[n_] := Module[{d = IntegerDigits[n, 2], m}, EvenQ @ (m = Length @ d) && Count[d, 1] == m/2]; Select[Range[12000], balQ[#] && balQ[#^2] &] (* Amiram Eldar, Apr 26 2022 *)
PROG
(Python)
from itertools import count, islice
from sympy.utilities.iterables import multiset_permutations
def isbalanced(n): b = bin(n)[2:]; return b.count("0") == b.count("1")
def A031443gen(): yield from (int("1"+"".join(p), 2) for n in count(1) for p in multiset_permutations("0"*n+"1"*(n-1)))
def agen():
for k in A031443gen():
if isbalanced(k**2):
yield k
print(list(islice(agen(), 40))) # Michael S. Branicky, Apr 26 2022
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Alex Ratushnyak, Apr 26 2022
STATUS
approved