[go: up one dir, main page]

login
Search: a062153 -id:a062153
     Sort: relevance | references | number | modified | created      Format: long | short | data
Number of digits in ternary representation of n.
+10
37
1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
OFFSET
0,4
COMMENTS
a(n) is the length of row n in table A054635. - Reinhard Zumkeller, Sep 05 2014
LINKS
Eric Weisstein's World of Mathematics, Ternary.
FORMULA
a(n) = A062153(n) + 1 for n >= 1.
a(n) = A077267(n) + A062756(n) + A081603(n);
From Reinhard Zumkeller, Oct 19 2007: (Start)
0 <= A134021(n) - a(n) <= 1;
a(A134025(n)) = A134021(A134025(n));
a(A134026(n)) = A134021(A134026(n)) - 1. (End)
a(n+1) = -Sum_{k=1..n} mu(3*k)*floor(n/k). - Benoit Cloitre, Oct 21 2009
a(n) = floor(log_3(n)) + 1. - Can Atilgan and Murat Erşen Berberler, Dec 05 2012
a(n) = if n < 3 then 1 else a(floor(n/3)) + 1. - Reinhard Zumkeller, Sep 05 2014
G.f.: 1 + (1/(1 - x))*Sum_{k>=0} x^(3^k). - Ilya Gutkovskiy, Jan 08 2017
EXAMPLE
a(8) = 2 because 8 = 22_3, having 2 digits.
a(9) = 3 because 9 = 100_3, having 3 digits.
MAPLE
A081604 := proc(n)
max(1, 1+ilog[3](n)) ;
end proc: # R. J. Mathar, Jul 12 2016
MATHEMATICA
Table[Length[IntegerDigits[n, 3]], {n, 0, 99}] (* Alonso del Arte, Dec 30 2012 *)
Join[{1}, IntegerLength[Range[120], 3]] (* Harvey P. Dale, Apr 07 2019 *)
PROG
(Haskell)
a081604 n = if n < 3 then 1 else a081604 (div n 3) + 1
-- Reinhard Zumkeller, Sep 05 2014, Feb 21 2013
KEYWORD
nonn,base
AUTHOR
Reinhard Zumkeller, Mar 23 2003
STATUS
approved
Positive part of inverse of A117966; write n in balanced ternary and then replace (-1)'s with 2's.
+10
24
0, 1, 5, 3, 4, 17, 15, 16, 11, 9, 10, 14, 12, 13, 53, 51, 52, 47, 45, 46, 50, 48, 49, 35, 33, 34, 29, 27, 28, 32, 30, 31, 44, 42, 43, 38, 36, 37, 41, 39, 40, 161, 159, 160, 155, 153, 154, 158, 156, 157, 143, 141, 142, 137, 135, 136, 140, 138, 139, 152, 150, 151, 146
OFFSET
0,3
REFERENCES
D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, Vol. 2, pp. 173-175
FORMULA
a(0) = 0, a(3n) = 3a(n), a(3n+1) = 3a(n)+1, a(3n-1) = 3a(n)+2.
If one adds this clause, then the function is defined on the whole Z: If n<0, then a(n) = A004488(a(-n)) (or equivalently: a(n) = A117968(-n)) and then it holds that a(A117966(n)) = n. - Antti Karttunen, May 19 2008
EXAMPLE
7 in balanced ternary is 1(-1)1, changing to 121 ternary is 16, so a(7)=16.
MAPLE
a:= proc(n) local d, i, m, r; m:=n; r:=0;
for i from 0 while m>0 do
d:= irem(m, 3, 'm');
if d=2 then m:=m+1 fi;
r:= r+d*3^i
od; r
end:
seq(a(n), n=0..100); # Alois P. Heinz, May 11 2015
MATHEMATICA
a[n_] := Module[{d, i, m = n, r = 0}, For[i = 0, m > 0, i++, {m, d} = QuotientRemainder[m, 3]; If[d == 2, m++]; r = r + d*3^i]; r];
a /@ Range[0, 100] (* Jean-François Alcover, Jan 05 2021, after Alois P. Heinz *)
PROG
(Scheme)
(Two alternative definitions in MIT/GNU Scheme, defined for whole Z:)
(define (A117967 z) (cond ((zero? z) 0) ((negative? z) (A004488 (A117967 (- z)))) (else (let* ((lp3 (expt 3 (A062153 z))) (np3 (* 3 lp3))) (if (< (* 2 z) np3) (+ lp3 (A117967 (- z lp3))) (+ np3 (A117967 (- z np3))))))))
(define (A117967v2 z) (cond ((zero? z) 0) ((negative? z) (A004488 (A117967v2 (- z)))) ((zero? (modulo z 3)) (* 3 (A117967v2 (/ z 3)))) ((= 1 (modulo z 3)) (+ (* 3 (A117967v2 (/ (- z 1) 3))) 1)) (else (+ (* 3 (A117967v2 (/ (+ z 1) 3))) 2))))
;; Antti Karttunen, May 19 2008
(Python)
from sympy.ntheory.factor_ import digits
def a004488(n): return int("".join([str((3 - i)%3) for i in digits(n, 3)[1:]]), 3)
def a117968(n):
if n==1: return 2
if n%3==0: return 3*a117968(n/3)
elif n%3==1: return 3*a117968((n - 1)/3) + 2
else: return 3*a117968((n + 1)/3) + 1
def a(n): return 0 if n==0 else a004488(a117968(n)) # Indranil Ghosh, Jun 06 2017
CROSSREFS
Cf. A117966. a(n) = A004488(A117968(n)). Bisection of A140263. A140267 gives the same sequence in ternary.
KEYWORD
base,nonn,look
AUTHOR
STATUS
approved
a(n) = floor(log_4(n)).
+10
14
0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
OFFSET
1,16
FORMULA
G.f.: (1/(1 - x))*Sum_{k>=1} x^(4^k). - Ilya Gutkovskiy, Jan 08 2017
PROG
(Magma) [ Ilog(4, n) : n in [1..150] ];
(PARI) a(n)=#digits(n, 4)-1 \\ Twice as fast as a(n)=for(i=0, n, (n>>=2)||return(i)); the naïve code a(n)=log(n)\log(4) works for standard realprecision=28 only up to n=4^47-5 and it is slower by another factor 2. - M. F. Hasler, Mar 11 2015
(PARI) A102572(n)=logint(n, 4) \\ M. F. Hasler, Nov 07 2019
CROSSREFS
KEYWORD
nonn
AUTHOR
N. J. A. Sloane, Dec 23 2006
STATUS
approved
a(n) = floor( n + log(n) ).
+10
11
1, 2, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 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, 54, 55, 56, 57, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70
OFFSET
1,2
COMMENTS
Complement of A045650. - Michel Marcus, Jun 30 2015
LINKS
MATHEMATICA
Table[Floor[n + Log[n]], {n, 100}] (* T. D. Noe, May 21 2012 *)
PROG
(PARI) a(n)=n+log(n)\1 \\ Charles R Greathouse IV, Aug 07 2012
(Magma) [Floor(n+Log(n)): n in [1..80]]; // Vincenzo Librandi, Feb 15 2013
KEYWORD
nonn,easy
AUTHOR
Mohammad K. Azarian, May 17 2012
STATUS
approved
Distance to nearest power of 3.
+10
10
0, 1, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 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, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7
OFFSET
1,5
FORMULA
a(n) = min(n-3^floor(log(n)/log(3)), 3*3^floor(log(n)/log(3))-n).
From Peter Bala, Sep 30 2022: (Start)
a(n) = n - A006166(n); a(n) = 2*n - A003605(n).
a(1) = 0, a(2) = 1, a(3) = 0; thereafter, a(3*n) = 3*a(n), a(3*n+1) = 2*a(n) + a(n+1) and a(3*n+2) = a(n) + 2*a(n+1). (End)
EXAMPLE
a(7) = 2 since 9 is closest power of 3 to 7 and 9 - 7 = 2.
MAPLE
a:= n-> (h-> min(n-h, 3*h-n))(3^ilog[3](n)):
seq(a(n), n=1..100); # Alois P. Heinz, Mar 28 2021
MATHEMATICA
Flatten[Table[Join[Range[0, 3^n], Range[3^n-1, 1, -1]], {n, 0, 4}]] (* Harvey P. Dale, Dec 31 2013 *)
PROG
(PARI) a(n) = my (p=#digits(n, 3)); return (min(n-3^(p-1), 3^p-n)) \\ Rémy Sigrist, Mar 24 2018
(Python)
def A081134(n):
kmin, kmax = 0, 1
while 3**kmax <= n:
kmax *= 2
while True:
kmid = (kmax+kmin)//2
if 3**kmid > n:
kmax = kmid
else:
kmin = kmid
if kmax-kmin <= 1:
break
return min(n-3**kmin, 3*3**kmin-n) # Chai Wah Wu, Mar 31 2021
KEYWORD
easy,nonn
AUTHOR
Klaus Brockhaus, Mar 08 2003
STATUS
approved
Ceiling(5n + log(5n)).
+10
10
7, 13, 18, 23, 29, 34, 39, 44, 49, 54, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 156, 161, 166, 171, 176, 181, 186, 191, 196, 201, 206, 211, 216, 221, 226, 231, 236, 241, 246, 251, 256, 261, 266, 271, 276, 281
OFFSET
1,1
LINKS
MATHEMATICA
Table[Ceiling[5*n + Log[5*n]], {n, 100}] (* T. D. Noe, May 21 2012 *)
PROG
(Magma) [Ceiling(5*n + Log(5*n)): n in [1..80]]; // Vincenzo Librandi, Feb 14 2013
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Mohammad K. Azarian, May 17 2012
STATUS
approved
a(n) = ceiling(4n + log(4n)).
+10
8
6, 11, 15, 19, 23, 28, 32, 36, 40, 44, 48, 52, 56, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, 129, 133, 137, 141, 145, 149, 153, 158, 162, 166, 170, 174, 178, 182, 186, 190, 194, 198, 202, 206, 210, 214, 218, 222, 226, 230
OFFSET
1,1
LINKS
MATHEMATICA
Table[Ceiling[4*n + Log[4*n]], {n, 100}] (* T. D. Noe, May 21 2012 *)
PROG
(Magma) [Ceiling(4*n + Log(4*n)): n in [1..80]]; // Vincenzo Librandi, Feb 14 2013
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Mohammad K. Azarian, May 17 2012
STATUS
approved
Ceiling(2n + log(2n)).
+10
7
3, 6, 8, 11, 13, 15, 17, 19, 21, 23, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129
OFFSET
1,1
LINKS
MATHEMATICA
Table[Ceiling[2*n + Log[2*n]], {n, 100}] (* T. D. Noe, May 21 2012 *)
PROG
(Magma) [Ceiling(2*n + Log(2*n)): n in [1..80]]; // Vincenzo Librandi, Feb 14 2013
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Mohammad K. Azarian, May 17 2012
STATUS
approved
Ceiling(3n + log(3n)).
+10
7
5, 8, 12, 15, 18, 21, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58, 62, 65, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95, 98, 101, 104, 107, 110, 113, 116, 119, 122, 125, 128, 131, 134, 137, 140, 143, 146, 149, 152, 156, 159, 162, 165, 168, 171, 174, 177, 180
OFFSET
1,1
LINKS
MATHEMATICA
Table[Ceiling[3*n + Log[3*n]], {n, 100}] (* T. D. Noe, May 21 2012 *)
PROG
(Magma) [Ceiling(3*n + Log(3*n)): n in [1..80]]; // Vincenzo Librandi, Feb 14 2013
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Mohammad K. Azarian, May 17 2012
STATUS
approved
Floor(2n + log(2n)).
+10
6
2, 5, 7, 10, 12, 14, 16, 18, 20, 22, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128
OFFSET
1,1
LINKS
MATHEMATICA
Table[Floor[2*n + Log[2*n]], {n, 100}] (* T. D. Noe, May 21 2012 *)
PROG
(Magma) [Floor(2*n + Log(2*n)): n in [1..80]]; // Vincenzo Librandi, Feb 15 2013
(PARI) a(n)=2*n+log(2*n)\1 \\ Charles R Greathouse IV, Sep 04 2015
KEYWORD
nonn,easy
AUTHOR
Mohammad K. Azarian, May 17 2012
STATUS
approved

Search completed in 0.016 seconds