|
|
A353158
|
|
a(n) is the distance from n to the nearest integer that can be added to n without carries in base 3.
|
|
3
|
|
|
0, 0, 1, 0, 0, 2, 3, 2, 1, 0, 0, 1, 0, 0, 2, 4, 6, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 1, 0, 0, 2, 3, 2, 1, 0, 0, 1, 0, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 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
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
0,6
|
|
LINKS
|
|
|
FORMULA
|
|
|
EXAMPLE
|
For n = 42:
- the numbers k around 42, alongside their distance to 42, ternary expansion and whether they require carries when added to 42, are:
k d ter(k) carries?
-- - ------ --------
38 4 1102 no
39 3 1110 yes
40 2 1111 yes
41 1 1112 yes
42 0 1120 yes
43 1 1121 yes
44 2 1122 yes
45 3 1200 yes
46 4 1201 yes
- so a(42) = 4.
|
|
PROG
|
(PARI) ok(u, v) = sumdigits(u+v, 3)==sumdigits(u, 3)+sumdigits(v, 3)
a(n) = { for (d=0, oo, if (ok(n, n-d) || ok(n, n+d), return (d))) }
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn,base
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|