login
Difference between 2^n and the next smaller or equal power of 3.
6

%I #20 Apr 16 2023 16:09:31

%S 0,1,1,5,7,5,37,47,13,269,295,1319,1909,1631,9823,13085,6487,72023,

%T 84997,347141,517135,502829,2599981,3605639,2428309,19205525,24062143,

%U 5077565,139295293,149450423,686321335,985222181,808182895,5103150191,6719515981,2978678759

%N Difference between 2^n and the next smaller or equal power of 3.

%C Sequence generalized : a(n) = A^n - B^(floor(log_B (A^n))) where A, B are integers. This sequence has A = 2, B = 3; A056577 has A = 3, B = 2. - _Ctibor O. Zizka_, Mar 03 2008

%H Alois P. Heinz, <a href="/A063005/b063005.txt">Table of n, a(n) for n = 0..3324</a>

%F a(n) = 2^n - 3^(floor (log_3 (2^n))).

%F a(n) = A000079(n) - 3^A136409(n). - _Michel Marcus_, Nov 19 2021

%p a:= n-> (t-> t-3^ilog[3](t))(2^n):

%p seq(a(n), n=0..40); # _Alois P. Heinz_, Oct 11 2019

%t a[n_] := 2^n - 3^Floor[Log[3, 2] * n]; Array[a, 36, 0] (* _Amiram Eldar_, Nov 19 2021 *)

%o (PARI) for(n=0,50,print1(2^n-3^floor(log(2^n)/log(3))","))

%o (Python)

%o def a(n):

%o m, p, target = 0, 1, 2**n

%o while p <= target: m += 1; p *= 3

%o return target - 3**(m-1)

%o print([a(n) for n in range(36)]) # _Michael S. Branicky_, Nov 19 2021

%Y Cf. A056577, A063003, A063004.

%Y Cf. A000079 (2^n), A000244 (3^n), A136409.

%K easy,nonn

%O 0,4

%A _Jens Voß_, Jul 02 2001

%E More terms from _Ralf Stephan_, Mar 20 2003