login
A365459
a(n) = n - the largest power of 3 that is less than or equal to n.
4
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,5
LINKS
Michael De Vlieger, Table of n, a(n) for n = 1..19683 (3^9 = 19683).
FORMULA
a(n) = n - A365458(n).
a(n) = n - 3^floor((log n)/(log 3)). - Michael De Vlieger, Sep 17 2023
MATHEMATICA
Array[# - 3^Floor@ Log[3, #] &, 88] (* Michael De Vlieger, Sep 17 2023 *)
PROG
(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
CROSSREFS
Cf. A000244, A053735 (gives the number of iterations needed to reach 0), A365458.
Sequence in context: A260187 A257687 A309957 * A220660 A257846 A203572
KEYWORD
nonn
AUTHOR
Antti Karttunen, Sep 17 2023
STATUS
approved