login
a(n) = smallest m such that wt(m^2) = n (where wt(i) = A000120(i)), or -1 if no such m exists.
8

%I #31 Dec 25 2022 13:50:33

%S 0,1,3,5,13,11,21,39,45,75,155,217,331,181,627,923,1241,2505,3915,

%T 5221,6475,11309,15595,19637,31595,44491,69451,113447,185269,244661,

%U 357081,453677,1015143,908091,980853,2960011,4568757,2965685,5931189,11862197,20437147

%N a(n) = smallest m such that wt(m^2) = n (where wt(i) = A000120(i)), or -1 if no such m exists.

%C Conjecture: a(n) is never -1. (It seems likely that the arguments of Lindström (1997) could be modified to establish this conjecture.)

%C a(n) is the smallest m such that A159918(m) = n (or -1 if ...).

%H Hugo Pfoertner, <a href="/A231897/b231897.txt">Table of n, a(n) for n = 0..110</a> (terms 0..70 from Donovan Johnson, significant extension enabled by programs provided in Code Golf challenge).

%H Code Golf Stackexchange, <a href="https://codegolf.stackexchange.com/questions/255529/smallest-and-largest-100-bit-square-with-maximum-hamming-weight">Smallest and largest 100-bit square with maximum Hamming weight</a>, fastest code challenge started Dec 15 2022.

%H Bernt Lindström, <a href="http://dx.doi.org/10.1006/jnth.1997.2129">On the binary digits of a power</a>, Journal of Number Theory, Volume 65, Issue 2, August 1997, Pages 321-324.

%F a(n) = 2*A211201(n-1) + 1 for n >= 1. - _Hugo Pfoertner_, Feb 06 2022

%o (Haskell)

%o a231897 n = head [x | x <- [1..], a159918 x == n]

%o -- _Reinhard Zumkeller_, Nov 20 2013

%o (PARI) a(n)=if(n,my(k); while(hammingweight(k++^2)!=n,); k, 0) \\ _Charles R Greathouse IV_, Aug 06 2015

%o (Python)

%o def wt(n): return bin(n).count('1')

%o def a(n):

%o m = 2**(n//2) - 1

%o while wt(m**2) != n: m += 1

%o return m

%o print([a(n) for n in range(32)]) # _Michael S. Branicky_, Feb 06 2022

%Y Cf. A000120, A159918, A230097, A211201, A231898, A214560.

%Y A089998 are the corresponding squares.

%K nonn

%O 0,3

%A _N. J. A. Sloane_, Nov 19 2013

%E a(26)-a(40) from _Reinhard Zumkeller_, Nov 20 2013