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.
%I A365459 #16 Sep 17 2023 18:24:25 %S A365459 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, %T A365459 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, %U A365459 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 %N A365459 a(n) = n - the largest power of 3 that is less than or equal to n. %H A365459 Michael De Vlieger, <a href="/A365459/b365459.txt">Table of n, a(n) for n = 1..19683</a> (3^9 = 19683). %F A365459 a(n) = n - A365458(n). %F A365459 a(n) = n - 3^floor((log n)/(log 3)). - _Michael De Vlieger_, Sep 17 2023 %t A365459 Array[# - 3^Floor@ Log[3, #] &, 88] (* _Michael De Vlieger_, Sep 17 2023 *) %o A365459 (PARI) A365459(n) = if(1==n,0,my(k=0); while((3^k) < n, k++); if((3^k) > n,k--); n-(3^k)); %o A365459 (Python) %o A365459 def A365459(n): %o A365459 kmin, kmax = 0, 1 %o A365459 while 3**kmax <= n: %o A365459 kmax <<= 1 %o A365459 while True: %o A365459 kmid = kmax+kmin>>1 %o A365459 if 3**kmid > n: %o A365459 kmax = kmid %o A365459 else: %o A365459 kmin = kmid %o A365459 if kmax-kmin <= 1: %o A365459 break %o A365459 return n-3**kmin # _Chai Wah Wu_, Sep 17 2023 %Y A365459 Cf. A000244, A053735 (gives the number of iterations needed to reach 0), A365458. %K A365459 nonn %O A365459 1,5 %A A365459 _Antti Karttunen_, Sep 17 2023