%I #19 May 05 2023 12:28:06
%S 0,1,3,5,9,11,33,19,21,35,39,37,45,43,69,73,93,77,75,83,189,85,141,
%T 139,153,151,147,155,267,149,165,173,279,275,171,283,315,277,537,325,
%U 297,293,579,301,309,365,333,299,567,331,339,553,549,563,1275,341,585,565,615,629
%N a(n) is the smallest number k such that A002487(k) = n.
%H Charles R Greathouse IV, <a href="/A020946/b020946.txt">Table of n, a(n) for n = 0..10000</a>
%e A002487(33) = 6 and this is the first time 6 appears, so a(6) = 33.
%t aa = {}; a[0] = 0; a[1] = 1; a[n_] := a[n] = If[EvenQ[n], a[n/2], a[(n - 1)/2] + a[(n + 1)/2]]; Do[k = 0; While[a[k] != p, k++]; AppendTo[aa, k], {p, 0, 100}]; aa (* _Artur Jasinski_, Dec 06 2010 *)
%o (PARI) fusc(n)={my(a=1, b=0);while(n,if(bitand(n, 1), b+=a, a+=b);n>>=1); b};
%o list(N)={
%o my(v=vector(N),k);
%o forstep(n=1,9e99,2,
%o k=fusc(n);
%o if(k<=N && !v[k],
%o v[k]=n;
%o if(vecmin(v),return(v))
%o )
%o )
%o }; \\ _Charles R Greathouse IV_, Dec 20 2011
%o (Python)
%o from itertools import count
%o from functools import reduce
%o def A020946(n): return next(filter(lambda k:sum(reduce(lambda x,y:(x[0],x[0]+x[1]) if int(y) else (x[0]+x[1],x[1]),bin(k)[-1:2:-1],(1,0)))==n,count(1))) if n else 0 # _Chai Wah Wu_, May 05 2023
%Y Equals A020950 + 1.
%Y Cf. A020943-A020945, A002487, A020947-A020950.
%K nonn
%O 0,3
%A _N. J. A. Sloane_ and _David W. Wilson_, Jun 27 2002