Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).
%I #41 Oct 18 2022 01:43:03
%S 0,23,111,479,1471,6015,24319,28415,114175,457727,490495,1964031,
%T 6025215,8122367,32497663,98549759,132104191,528449535,1593769983,
%U 1862205439,7448952831,25635323903,29930291199,119721689087,411242070015,479961546751,514321285119,2057287237631,7687987265535
%N a(n) is the least number k such that (the binary weight of k) - (the binary weight of k^2) = n.
%C Note that the terms of A260986 with n > 1 can all be found here. Terms here that are not in A260986 have the property not to be a record value of the ratio (binary weight k) / (binary weight k^2).
%C Observation: The difference of two neighboring terms is a multiple of 2^(number of the ones after the last zero in binary expression of the smaller term).
%H K. B. Stolarsky, <a href="http://dx.doi.org/10.1090/S0002-9939-1978-0495823-5">The binary digits of a power</a>, Proc. Amer. Math. Soc. 71 (1978), pp. 1-5.
%e -----------------------------------------------------------------------------
%e n k k^2 binary k binary k^2
%e -----------------------------------------------------------------------------
%e 0 0 0 0 0
%e 1 23 529 10111 1000010001
%e 2 111 12321 1101111 11000000100001
%e 3 479 229441 111011111 111000000001000001
%e 4 1471 2163841 10110111111 1000010000010010000001
%e 5 6015 36180225 1011101111111 10001010000001000100000001
%e 6 24319 591413761 101111011111111 100011010000000100001000000001
%e 7 28415 807412225 110111011111111 110000001000000010001000000001
%e 8 114175 13035930625 11011110111111111 1100001001000000001000010000000001
%t a[0] = 0; a[n_] := a[n] = Module[{step = If[n == 1, 1, 2^Length[Split[IntegerDigits[a[n - 1], 2]][[-1]]]], k = a[n - 1]}, While[DigitCount[k, 2, 1] - DigitCount[k^2, 2, 1] != n, k += step]; k]; Array[a, 23, 0] (* _Amiram Eldar_, Oct 14 2022 *)
%o (PARI) a(n) = my(k=0); while(hammingweight(k) - hammingweight(k^2) != n, k++); k; \\ _Michel Marcus_, Oct 14 2022
%o (Python)
%o A356877 = [0]
%o for n in range(1,29):
%o s, k = -1, A356877[-1]
%o while bin(A356877[-1])[s] == "1": s -= 1
%o while bin(k)[2:].count("1")-bin(k**2)[2:].count("1") != n: k += 2**(abs(s)-1)
%o A356877.append(k)
%o print(A356877)
%Y Cf. A000120, A159918, A260986, A357750.
%K nonn,base
%O 0,2
%A _Karl-Heinz Hofmann_, Oct 10 2022