%I #17 Jan 04 2023 02:04:37
%S 1,2,1,-1,1,2,1,2,1,2,1,-1,1,2,1,-1,1,2,1,-1,1,2,1,2,1,2,1,-1,1,2,1,2,
%T 1,2,1,-1,1,2,1,2,1,2,1,-1,1,2,1,-1,1,2,1,-1,1,2,1,2,1,2,1,-1,1,2,1,
%U -1,1,2,1,-1,1,2,1,2,1,2,1,-1,1,2,1,-1,1,2,1,-1,1,2,1,2,1,2,1,-1,1,2,1,2,1,2,1,-1,1,2,1,2,1,2,1,-1,1,2,1,-1,1,2,1,-1,1,2
%N a(1) = 1 then a(n) = a(n-1) - (-1)^ceiling(n/2)*a(floor(n/2)).
%C The asymptotic density of the occurrences of -1, 1, and 2 are 1/6, 1/2, and 1/3, respectively. - _Amiram Eldar_, Nov 30 2022
%H Andrew Howroyd, <a href="/A105931/b105931.txt">Table of n, a(n) for n = 1..1000</a>
%F abs(a(n)) = A056832(n).
%F a(k) = -1 iff k is in 4*A003159.
%F From _Amiram Eldar_, Nov 30 2022: (Start)
%F Multiplicative with a(2^e) = 2 if e is odd and -1 if e is even, and a(p^e) = 1 for p > 2.
%F Asymptotic mean: Limit_{m->oo} (1/m) * Sum_{k=1..m} a(k) = 1. (End)
%F Dirichlet g.f.: zeta(s)*(4^s+2^(s+1)-2)/(4^s+2^s). - _Amiram Eldar_, Jan 04 2023
%t a[n_] := Module[{e = IntegerExponent[n, 2]}, If[e > 0, If[Mod[e, 2] == 1, 2, -1], 1]]; Array[a, 100] (* _Amiram Eldar_, Nov 30 2022 after the second PARI code *)
%o (PARI) a(n)=if(n<2,1,a(n-1)-(-1)^ceil(n/2)*a(floor(n/2)))
%o (PARI) a(n)={my(e=valuation(n, 2)); if(e>0, if(e%2, 2, -1), 1)} \\ _Andrew Howroyd_, Aug 06 2018
%Y Cf. A056832, A003159.
%K sign,mult
%O 1,2
%A _Benoit Cloitre_, Apr 26 2005
|