OFFSET
1,1
LINKS
Alois P. Heinz, Table of n, a(n) for n = 1..10000
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
CROSSREFS
KEYWORD
base,easy,nonn
AUTHOR
Erich Friedman, Jun 16 2001
EXTENSIONS
Offset changed to 1 by Alois P. Heinz, May 10 2015
STATUS
approved