OFFSET
0,3
COMMENTS
a(n) = How many numbers whose base-3 representation begins with digit "2" are encountered before (3^n)-1 is reached when starting from k = (3^(n+1))-1 and repeatedly applying the map that replaces k by k - (sum of digits in base-3 representation of k). Note that (3^n)-1 (in base-3: "222...", with digit "2" repeated n times) is not included in the count, although the starting point (3^(n+1))-1 is.
EXAMPLE
For n=0, we start from 3^(0+1) - 1 = 2 (also "2" in base-3), and subtract 2 to get 0, which doesn't begin with 2, thus a(0) = 1.
For n=1, we start from 3^(1+1) - 1 = 8 ("22" in base-3), and subtract 2*2 = 4 to get 4 ("11" in base-3) which doesn't begin with 2, thus a(1) = 1.
For n=2, we start from 3^(2+1) - 1 = 26 ("222" in base-3), and subtract first 6 to get 20 ("202" in base-3), from which we subtract 4, to get 16 ("121" in base-3), so in two steps we have reached the first such number that does not begin with "2" in base-3, thus a(2) = 2.
MATHEMATICA
Flatten@ Table[FirstPosition[#, k_ /; k != 2] &@ Map[First@ IntegerDigits[#, 3] &, NestWhileList[# - Total@ IntegerDigits[#, 3] &, 3^(n + 1) - 1, # > 3^n - 1 &]] - 1, {n, 0, 16}] (* Michael De Vlieger, Jun 27 2016, Version 10 *)
PROG
(C) /* Use the C-program given in A261234. */
(Scheme) (definec (A261237 n) (let loop ((k (- (A000244 (+ 1 n)) 1)) (s 0)) (if (< (A122586 k) 2) s (loop (* 2 (A054861 k)) (+ 1 s)))))
(PARI) a(n)=my(k=3^(n+1)-1, t=2*3^n, s); while(k>=t, k-=sumdigits(k, 3); s++); s \\ Charles R Greathouse IV, Aug 21 2015
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, Aug 16 2015
EXTENSIONS
Terms a(24) & a(25) from Antti Karttunen, Jun 27 2016
STATUS
approved