cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A319021 Next larger integer with same sum of digits in base 3 as n.

Original entry on oeis.org

3, 4, 9, 6, 7, 10, 11, 14, 27, 12, 13, 18, 15, 16, 19, 20, 23, 28, 21, 22, 29, 24, 25, 32, 35, 44, 81, 30, 31, 36, 33, 34, 37, 38, 41, 54, 39, 40, 45, 42, 43, 46, 47, 50, 55, 48, 49, 56, 51, 52, 59, 62, 71, 82, 57, 58, 63, 60, 61, 64, 65, 68, 83, 66, 67, 72
Offset: 1

Views

Author

Rémy Sigrist, Sep 08 2018

Keywords

Comments

This sequence is the base-3 variant of A057168 (base-2) and of A228915 (base-10).
All integers except those in A062318 appear in this sequence.

Examples

			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
		

Crossrefs

Programs

  • 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 *)
  • 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

Formula

a(3^k) = 3^(k+1) for any k >= 0.
A053735(a(n)) = A053735(n).