login
a(n) is the distance from n to the nearest integer that can be added to n without carries in base 3.
3

%I #12 May 01 2022 11:42:44

%S 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,

%T 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,

%U 21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4

%N a(n) is the distance from n to the nearest integer that can be added to n without carries in base 3.

%H Rémy Sigrist, <a href="/A353158/b353158.txt">Table of n, a(n) for n = 0..9841</a>

%F a(n) = 0 iff n belongs to A005836.

%e For n = 42:

%e - the numbers k around 42, alongside their distance to 42, ternary expansion and whether they require carries when added to 42, are:

%e k d ter(k) carries?

%e -- - ------ --------

%e 38 4 1102 no

%e 39 3 1110 yes

%e 40 2 1111 yes

%e 41 1 1112 yes

%e 42 0 1120 yes

%e 43 1 1121 yes

%e 44 2 1122 yes

%e 45 3 1200 yes

%e 46 4 1201 yes

%e - so a(42) = 4.

%o (PARI) ok(u,v) = sumdigits(u+v,3)==sumdigits(u,3)+sumdigits(v,3)

%o a(n) = { for (d=0, oo, if (ok(n, n-d) || ok(n, n+d), return (d))) }

%Y Cf. A005836 (positions of zeros), A167877, A353157 (binary variant).

%K nonn,base

%O 0,6

%A _Rémy Sigrist_, Apr 27 2022