The OEIS mourns the passing of Jim Simons and is grateful to the Simons Foundation for its support of research in many branches of science, including the OEIS.
login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A365459 a(n) = n - the largest power of 3 that is less than or equal to n. 4

%I #16 Sep 17 2023 18:24:25

%S 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 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 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 a(n) = n - the largest power of 3 that is less than or equal to n.

%H Michael De Vlieger, <a href="/A365459/b365459.txt">Table of n, a(n) for n = 1..19683</a> (3^9 = 19683).

%F a(n) = n - A365458(n).

%F a(n) = n - 3^floor((log n)/(log 3)). - _Michael De Vlieger_, Sep 17 2023

%t Array[# - 3^Floor@ Log[3, #] &, 88] (* _Michael De Vlieger_, Sep 17 2023 *)

%o (PARI) A365459(n) = if(1==n,0,my(k=0); while((3^k) < n, k++); if((3^k) > n,k--); n-(3^k));

%o (Python)

%o def A365459(n):

%o kmin, kmax = 0, 1

%o while 3**kmax <= n:

%o kmax <<= 1

%o while True:

%o kmid = kmax+kmin>>1

%o if 3**kmid > n:

%o kmax = kmid

%o else:

%o kmin = kmid

%o if kmax-kmin <= 1:

%o break

%o return n-3**kmin # _Chai Wah Wu_, Sep 17 2023

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

%K nonn

%O 1,5

%A _Antti Karttunen_, Sep 17 2023

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified June 5 04:27 EDT 2024. Contains 373102 sequences. (Running on oeis4.)