OFFSET
1,1
COMMENTS
LINKS
Rémy Sigrist, Table of n, a(n) for n = 1..10000
EXAMPLE
The first terms, alongside the ternary representations of n and of a(n), are:
n a(n) ter(n) ter(a(n))
-- ---- ------ ---------
1 3 1 10
2 4 2 11
3 9 10 100
4 6 11 20
5 7 12 21
6 10 20 101
7 11 21 102
8 14 22 112
9 27 100 1000
10 12 101 110
11 13 102 111
12 18 110 200
13 15 111 120
14 16 112 121
15 19 120 201
MATHEMATICA
nli3[n_]:=Module[{nd3=Total[IntegerDigits[n, 3]], k=n+1}, While[Total[IntegerDigits[k, 3]]!=nd3, k++]; k]; Array[nli3, 70] (* Harvey P. Dale, Jun 27 2023 *)
PROG
(PARI) a(n, base=3) = my (c=0); for (w=0, oo, my (d=n % base); if (d+1 < base && c, return ((n+1)*base^w + ((c-1)%(base-1) + 1)*base^((c-1)\(base-1))-1), c += d; n \= base))
(Python)
def a(n, base=3):
c, b, w = 0, base, 0
while True:
d = n%b
if d+1 < b and c:
return (n+1)*b**w + ((c-1)%(b-1)+1)*b**((c-1)//(b-1))-1
c += d; n //= b; w += 1
print([a(n) for n in range(1, 67)]) # Michael S. Branicky, Jul 10 2022 after Rémy Sigrist
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Sep 08 2018
STATUS
approved