login
Smallest number whose digit sum is 3^n.
2

%I #14 Jul 03 2018 02:26:05

%S 1,3,9,999,999999999,999999999999999999999999999,

%T 999999999999999999999999999999999999999999999999999999999999999999999999999999999

%N Smallest number whose digit sum is 3^n.

%H Harry J. Smith, <a href="/A060712/b060712.txt">Table of n, a(n) for n = 0..8</a>

%t Do[ a = {}; While[ Apply[ Plus, a ] + 9 < 3^n, a = Append[ a, 9 ] ]; If[ Apply[ Plus, a ] != 3^n, a = Prepend[ a, 3^n - Apply[ Plus, a ] ] ]; Print[ FromDigits[ a ] ], {n, 1, 6} ]

%t Join[{1,3},Table[FromDigits[PadRight[{},3^(n-2),9]],{n,2,6}]] (* _Harvey P. Dale_, Jun 10 2015 *)

%o (PARI) { for (n=0, 8, s=3^n; x=s\9; d=s - 9*x; write("b060712.txt", n, " ", (d+1)*10^x - 1); ) } \\ _Harry J. Smith_, Jul 10 2009

%K nonn,base

%O 0,2

%A _Robert G. Wilson v_, Apr 21 2001