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
KEYWORD
nonn
AUTHOR
Antti Karttunen, Sep 17 2023
STATUS
approved