Displaying 1-10 of 28 results found.
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
LINKS
Eric Weisstein's World of Mathematics, Ternary.
FORMULA
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
EXAMPLE
a(8) = 2 because 8 = 22_3, having 2 digits.
a(9) = 3 because 9 = 100_3, having 3 digits.
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
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
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:
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];
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))))
(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
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
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
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
MATHEMATICA
Table[Floor[n + Log[n]], {n, 100}] (* T. D. Noe, May 21 2012 *)
CROSSREFS
Cf. A000523, A062153, A102572, A212446, A212447, A212448, A212449, A212450, A212451, A212452, A212453, A212454.
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
FORMULA
a(n) = min(n-3^floor(log(n)/log(3)), 3*3^floor(log(n)/log(3))-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)):
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)
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
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
MATHEMATICA
Table[Ceiling[5*n + Log[5*n]], {n, 100}] (* T. D. Noe, May 21 2012 *)
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
MATHEMATICA
Table[Ceiling[4*n + Log[4*n]], {n, 100}] (* T. D. Noe, May 21 2012 *)
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
MATHEMATICA
Table[Ceiling[2*n + Log[2*n]], {n, 100}] (* T. D. Noe, May 21 2012 *)
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
MATHEMATICA
Table[Ceiling[3*n + Log[3*n]], {n, 100}] (* T. D. Noe, May 21 2012 *)
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
MATHEMATICA
Table[Floor[2*n + Log[2*n]], {n, 100}] (* T. D. Noe, May 21 2012 *)
CROSSREFS
Cf. A000523, A062153, A102572, A212445, A212447, A212448, A212449, A212450, A212451, A212452, A212453, A212454.
Search completed in 0.016 seconds
|