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.

A365459 a(n) = n - the largest power of 3 that is less than or equal to n.

Original entry on oeis.org

0, 1, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 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, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 0, 1, 2, 3, 4, 5, 6, 7
Offset: 1

Views

Author

Antti Karttunen, Sep 17 2023

Keywords

Crossrefs

Cf. A000244, A053735 (gives the number of iterations needed to reach 0), A365458.

Programs

  • Mathematica
    Array[# - 3^Floor@ Log[3, #] &, 88] (* Michael De Vlieger, Sep 17 2023 *)
  • PARI
    A365459(n) = if(1==n,0,my(k=0); while((3^k) < n, k++); if((3^k) > n,k--); n-(3^k));
    
  • Python
    def A365459(n):
        kmin, kmax = 0, 1
        while 3**kmax <= n:
            kmax <<= 1
        while True:
            kmid = kmax+kmin>>1
            if 3**kmid > n:
                kmax = kmid
            else:
                kmin = kmid
            if kmax-kmin <= 1:
                break
        return n-3**kmin # Chai Wah Wu, Sep 17 2023

Formula

a(n) = n - A365458(n).
a(n) = n - 3^floor((log n)/(log 3)). - Michael De Vlieger, Sep 17 2023