%I #18 Jul 26 2022 15:55:04
%S 0,0,3,27,162,810,3645,15309,61236,236196,885735,3247695,11691702,
%T 41452398,145083393,502211745,1721868840,5854354056,19758444939,
%U 66248903619,220829678730,732224724210,2416341589893,7939408081077
%N a(n) = (1/2)*n*(n-1)*3^(n-1).
%C Number of inversions in all ternary words of length n on {0,1,2}. Example: a(2)=3 because each of the words 10,20,21 has one inversion and the words 00,01,02,11,12,22 have no inversions. a(n)=3*A027472(n+1). a(n)=Sum(k*A129529(n,k),k>=0).
%H Harvey P. Dale, <a href="/A129530/b129530.txt">Table of n, a(n) for n = 0..1000</a>
%H <a href="/index/Rec#order_03">Index entries for linear recurrences with constant coefficients</a>, signature (9,-27,27).
%F G.f.: 3x^2/(1-3x)^3.
%F a(0)=0, a(1)=0, a(2)=3, a(n)=9*a(n-1)-27*a(n-2)+27*a(n-3). - _Harvey P. Dale_, Dec 18 2013
%F From _Amiram Eldar_, Jan 12 2021: (Start)
%F Sum_{n>=2} 1/a(n) = 2 * (1 - 2 * log(3/2)).
%F Sum_{n>=2} (-1)^n/a(n) = 2*(4*log(4/3) - 1). (End)
%F a(n) = 3*A027472(n+1). - _R. J. Mathar_, Jul 26 2022
%p seq(n*(n-1)*3^(n-1)/2,n=0..27);
%t Table[(n(n-1)3^(n-1))/2,{n,0,30}] (* or *) LinearRecurrence[{9,-27,27},{0,0,3},30] (* _Harvey P. Dale_, Dec 18 2013 *)
%o (PARI) a(n)=n*(n-1)*3^(n-1)/2 \\ _Charles R Greathouse IV_, Oct 16 2015
%Y Cf. A027472, A129529, A001788, A129532.
%K nonn,easy
%O 0,3
%A _Emeric Deutsch_, Apr 22 2007