A261237 Number of steps needed when starting from (3^(n+1))-1 and repeatedly applying the map that replaces k with k - (sum of digits in base-3 representation of k) to encounter the first number whose base-3 representation begins with a digit other than 2.
1, 1, 2, 5, 13, 34, 92, 251, 687, 1885, 5184, 14292, 39557, 110094, 308351, 868716, 2458964, 6984467, 19890809, 56775186, 162427605, 465816503, 1339163192, 3858600035, 11138726760, 32199805820
Offset: 0
Examples
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.
Programs
-
C
/* Use the C-program given in A261234. */
-
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 *)
-
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
-
Scheme
(definec (A261237 n) (let loop ((k (- (A000244 (+ 1 n)) 1)) (s 0)) (if (< (A122586 k) 2) s (loop (* 2 (A054861 k)) (+ 1 s)))))
Extensions
Terms a(24) & a(25) from Antti Karttunen, Jun 27 2016
Comments