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.

A365458 The largest power of 3 that is less than or equal to n.

Original entry on oeis.org

1, 1, 3, 3, 3, 3, 3, 3, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 81, 81, 81, 81, 81
Offset: 1

Views

Author

Antti Karttunen, Sep 17 2023

Keywords

Examples

			a(2) = 1 because 3^0 = 1 <= 2.
a(3) = 3 because 3^1 = 3 <= 3.
a(4) = 3 because 3^1 = 3 <= 4.
		

Crossrefs

Programs

  • Mathematica
    Array[3^Floor@ Log[3, #] &, 90] (* Michael De Vlieger, Sep 17 2023 *)
  • PARI
    A365458(n) = if(1==n,n,my(k=0); while((3^k) < n, k++); if((3^k) > n,k--); (3^k));
    
  • PARI
    a(n) = 3^logint(n, 3); \\ Michel Marcus, Sep 17 2023
    
  • Python
    def A365458(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 3**kmin # Chai Wah Wu, Sep 17 2023

Formula

a(n) = 3^floor((log n) / (log 3)). - Michael De Vlieger, Sep 17 2023
a(n) = A000244(A062153(n)). - Michel Marcus, Sep 17 2023