%I #21 Nov 25 2019 00:59:43
%S 0,1,4,7,16,61,160,547,1456,5110,13120,44287,118096,398581,1075840,
%T 3720094,9565936,32285041,86093440,290565367,774840976,2711943430,
%U 7059662080,23535794707,61987278400,212693848522,564945153280,1979718703900,5083731656656
%N The rows of the binomial triangle reduced to balanced ternary lists encoded as decimal numbers.
%C Define an operation ~: ZxZ -> {-1,0,1} (Z integers) by b ~ n = (b sigmod n) [|b sigmod n|=1]. Here [] is the Iverson bracket and sigmod is the signed mod operation defined as b sigmod n = b - n*ceil(b/n - 1/2) if n <> 0 and b otherwise. Further let T(n) = list_{k=0..n-1} binomial(n-1,k) ~ n for n > 1 and n if n is 0 or 1. We call T(n) the binomial notation of n.
%C A non-obvious arithmetical property of the binomial triangle becomes apparent from these balanced ternary lists: the rows which have an odd prime number as an index and only these rows are represented by a ternary list where 1 and -1 are alternating. One might also say that an odd integer is prime iff n > 1 and its binomial notation is zerofree.
%C Finally a(n) = Sum_{k=0..n-1} T(n)[k]*3^k.
%C The sequence starts at n=0 although the definitions can be extended to the negative integers by flipping the signs of the ternary digits. To illustrate the definitions:
%C n T(n) a(n)
%C ----------------------------------
%C [-6] -1, 1, 0, 0, 1, -1 [-160]
%C [-5] -1, 1, -1, 1, -1 [ -61]
%C [-4] -1, 1, 1, -1 [ -16]
%C [-3] -1, 1, -1 [ -7]
%C [-2] -1, -1 [ -4]
%C [-1] -1 [ -1]
%C [ 0] 0 [ 0]
%C [ 1] 1 [ 1]
%C [ 2] 1, 1 [ 4]
%C [ 3] 1, -1, 1 [ 7]
%C [ 4] 1, -1, -1, 1 [ 16]
%C [ 5] 1, -1, 1, -1, 1 [ 61]
%C [ 6] 1, -1, 0, 0, -1, 1 [ 160]
%H Wikipedia, <a href="http://en.wikipedia.org/wiki/Balanced_ternary">Balanced ternary</a>
%p A182929 := proc(n) local lop, k, Tlist;
%p lop := proc(a,n) if n = 0 then a else mods(a,n);
%p `if`(abs(%)=1,%,0) fi end;
%p Tlist := proc(n) `if`(abs(n)<2,n,seq(signum(n)*
%p lop(binomial(abs(n)-1,k),n),k=0..abs(n)-1)) end:
%p [Tlist(n)]; signum(n)*add(3^k*%[k+1],k=0..abs(n)-1) end:
%p seq(A182929(n),n=0..30);
%t lop[a_, n_] := Module[{m}, m = If[n == 0, a, Mod[a, n, -Quotient[Abs[n]-1, 2]]]; If[Abs[m] == 1, m, 0]];
%t Tlist[n_] := If[Abs[n]<2, {n}, Table[Sign[n]*lop[Binomial[Abs[n]-1, k], n], {k, 0, Abs[n]-1}]];
%t a[n_] := Module[{t=Tlist[n]}, Sign[n]*Sum[3^k*t[[k+1]], {k, 0, Abs[n]-1}]];
%t Table[a[n], {n, 0, 30}] (* _Jean-François Alcover_, Jun 22 2019, from Maple *)
%o (PARI)
%o a(n) = {
%o if (n == 0, 0,
%o subst(apply(r->if(r==1,1,r==n-1,-1,0), lift(Mod(1+'x,n)^(n-1))), 'x, 3));
%o };
%o vector(29, n, a(n-1)) \\ _Gheorghe Coserea_, Nov 21 2016
%Y Cf. A007318, A047999, A001317.
%K nonn
%O 0,3
%A _Peter Luschny_, Mar 16 2011