login
A061656
Numbers k > 1 such that, in base 2, k and k^2 contain the same digits in the same proportion.
12
53, 106, 211, 212, 397, 403, 417, 419, 422, 424, 437, 441, 459, 781, 794, 801, 806, 817, 833, 834, 838, 839, 841, 844, 848, 865, 874, 882, 885, 918, 979, 1481, 1549, 1562, 1565, 1571, 1573, 1585, 1588, 1589, 1602, 1612, 1613, 1634, 1637, 1665, 1666, 1667, 1668
OFFSET
1,1
LINKS
EXAMPLE
53 = 110101_2 and 53^2 = 101011111001_2.
MAPLE
p:= n-> add(x^i, i=convert(n, base, 2)):
a:= proc(n) option remember; local k;
for k from 1+`if`(n=1, 0, a(n-1))
while p(k)*2<>p(k^2) do od; k
end:
seq(a(n), n=1..50); # Alois P. Heinz, May 10 2015
MATHEMATICA
b2pQ[n_]:=Module[{bn=IntegerDigits[n, 2], b2n=IntegerDigits[n^2, 2], cbn0, cb2n0}, cbn0=Count[bn, 0]; cb2n0=Count[b2n, 0]; cbn0>0&&cb2n0>0 && Count[ bn, 1]/cbn0==Count[b2n, 1]/cb2n0]; Select[Range[1700], b2pQ] (* Harvey P. Dale, Jan 25 2012 *)
PROG
(Python)
from fractions import Fraction
from itertools import count, islice
def f(i, j):
bi, bj = bin(i)[2:], bin(j)[2:]
pi = [Fraction(bi.count(d), len(bi)) for d in "01"]
pj = [Fraction(bj.count(d), len(bj)) for d in "01"]
return pi == pj
def ok(n): return f(n, n**2)
print([k for k in range(2, 1700) if ok(k)]) # Michael S. Branicky, Feb 27 2023
KEYWORD
base,easy,nonn
AUTHOR
Erich Friedman, Jun 16 2001
EXTENSIONS
Offset changed to 1 by Alois P. Heinz, May 10 2015
STATUS
approved