%I #14 Apr 02 2014 05:35:51
%S 5,7,11,15,19,21,29,33,45,55,57,63,83,87,99,135,163,165,171,189,245,
%T 249,261,297,405,487,489,495,513,567,731,735,747,783,891,1215,1459,
%U 1461,1467,1485,1539,1701,2189,2193,2205,2241,2349,2673,3645,4375,4377
%N Ternary expansion uses each positive digit just once.
%H Vincenzo Librandi, <a href="/A023741/b023741.txt">Table of n, a(n) for n = 1..2000</a>
%t Union[ Map[ Plus@@(Array[ (3^#)&, Length[ # ], 0 ]*#)&, Flatten[ Table[ Permutations[ Join[ Range[ 3-1 ], Array[ 0&, k ] ] ], {k, 0, 6} ], 1 ] ] ]
%o (PARI) a(n)=(1+(j(n)>=i(n)))*3^i(n)+(2-(j(n)>=i(n)))*3^(j(n)%i(n)) where i(n) = floor(1/2+sqrt(n)) and j(n) = n-1-2*binomial(i(n),2) /* _Michael Somos_, Jun 03 2000 */
%K nonn,base,easy
%O 1,1
%A _Olivier GĂ©rard_