

A081134


Distance to nearest power of 3.


6



0, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7
(list;
graph;
refs;
listen;
history;
text;
internal format)



OFFSET

1,5


COMMENTS

When using the formula to compute the sequence one must take precautions against disturbing effects of rounding errors (see program).


LINKS

Rémy Sigrist, Table of n, a(n) for n = 1..10000
Klaus Brockhaus, Illustration for A081134, A081249, A081250 and A081251
HsienKuei Hwang, S. Janson, T.H. Tsai, Exact and asymptotic solutions of the recurrence f(n) = f(floor(n/2)) + f(ceiling(n/2)) + g(n): theory and applications, Preprint 2016.
HsienKuei Hwang, S. Janson, T.H. Tsai, Exact and Asymptotic Solutions of a DivideandConquer Recurrence Dividing at Half: Theory and Applications, ACM Transactions on Algorithms, 13:4 (2017), #47; DOI: 10.1145/3127585.
Index entries for sequences related to distance to nearest element of some set


FORMULA

a(n) = min(n3^floor(log(n)/log(3)), 3*3^floor(log(n)/log(3))n).


EXAMPLE

a(7) = 2 since 9 is closest power of 3 to 7 and 9  7 = 2.


MATHEMATICA

Flatten[Table[Join[Range[0, 3^n], Range[3^n1, 1, 1]], {n, 0, 4}]] (* Harvey P. Dale, Dec 31 2013 *)


PROG

(PARI) for(n=1, 89, p=3^floor(0.1^25+log(n)/log(3)); print1(min(np, 3*pn), ", "))
(PARI) a(n) = my (p=#digits(n, 3)); return (min(n3^(p1), 3^pn)) \\ Rémy Sigrist, Mar 24 2018


CROSSREFS

Cf. A053646, A062153, A002452, A081249, A081250, A081251.
Sequence in context: A194526 A165033 A179766 * A017848 A108619 A091327
Adjacent sequences: A081131 A081132 A081133 * A081135 A081136 A081137


KEYWORD

easy,nonn


AUTHOR

Klaus Brockhaus, Mar 08 2003


STATUS

approved



