login
a(1)=1 then a(n)=a(n/2^k)+1 if n is even and 2^k is the largest power of 2 dividing n, a(n)=a(n-1) otherwise.
1

%I #18 Sep 10 2020 03:01:43

%S 1,2,2,2,2,3,3,2,2,3,3,3,3,4,4,2,2,3,3,3,3,4,4,3,3,4,4,4,4,5,5,2,2,3,

%T 3,3,3,4,4,3,3,4,4,4,4,5,5,3,3,4,4,4,4,5,5,4,4,5,5,5,5,6,6,2,2,3,3,3,

%U 3,4,4,3,3,4,4,4,4,5,5,3,3,4,4,4,4,5,5,4,4,5,5,5,5,6,6,3,3,4,4,4,4,5,5,4,4

%N a(1)=1 then a(n)=a(n/2^k)+1 if n is even and 2^k is the largest power of 2 dividing n, a(n)=a(n-1) otherwise.

%H Robert Israel, <a href="/A081743/b081743.txt">Table of n, a(n) for n = 1..10000</a>

%F a(n) = A000120(n) + A059841(n). - _Robert Israel_, Sep 09 2020

%p a:= proc(n) option remember;

%p if n::even then 1+procname(n/2^padic:-ordp(n,2)) else procname(n-1) fi

%p end proc:

%p a(1):= 1:

%p map(a, [$1..200]); # _Robert Israel_, Sep 09 2020

%t Nest[Append[#1, If[EvenQ@ #2, 1 + #1[[#2/2^IntegerExponent[#2, 2]]], #1[[-1]] ]] & @@ {#, Length@ # + 1} &, {1}, 104] (* _Michael De Vlieger_, Sep 09 2020 *)

%o (PARI) a(n)=if(n<2, 1, if(n%2, a(n-1), a(n/2^valuation(n, 2))+1))

%Y Cf. A000120, A059841.

%K nonn

%O 1,2

%A _Benoit Cloitre_, Apr 07 2003