[go: up one dir, main page]

login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

Search: a289814 -id:a289814
     Sort: relevance | references | number | modified | created      Format: long | short | data
a(n) = Product_{d|n, d<n} A019565(A289814(d)); a product obtained from the 2-digits present in ternary expansions of proper divisors of n.
+20
13
1, 1, 1, 2, 1, 2, 1, 2, 1, 4, 1, 6, 1, 6, 2, 12, 1, 6, 1, 4, 3, 4, 1, 36, 2, 2, 1, 12, 1, 36, 1, 36, 2, 12, 6, 30, 1, 10, 1, 240, 1, 180, 1, 20, 6, 20, 1, 1620, 3, 60, 6, 60, 1, 30, 4, 72, 5, 4, 1, 360, 1, 2, 15, 72, 2, 180, 1, 36, 10, 144, 1, 2700, 1, 2, 90, 20, 6, 180, 1, 720, 1, 4, 1, 540, 12, 6, 2, 720, 1, 900, 3, 100, 1, 20, 10, 16200, 1, 60, 6
OFFSET
1,4
LINKS
FORMULA
a(n) = Product_{d|n, d<n} A019565(A289814(d)).
PROG
(PARI)
A019565(n) = {my(j, v); factorback(Mat(vector(if(n, #n=vecextract(binary(n), "-1..1")), j, [prime(j), n[j]])~))}; \\ This function from M. F. Hasler
A289814(n) = { my (d=digits(n, 3)); fromdigits(vector(#d, i, if (d[i]==2, 1, 0)), 2); } \\ From _Remy Sigrist_
A293222(n) = { my(m=1); fordiv(n, d, if(d < n, m *= A019565(A289814(d)))); m; };
CROSSREFS
Cf. A019565, A289814, A293221, A293224 (restricted growth sequence transform), A293226.
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, Oct 03 2017
STATUS
approved
a(n) = A289813(n) + A289814(n).
+20
10
0, 1, 1, 2, 3, 3, 2, 3, 3, 4, 5, 5, 6, 7, 7, 6, 7, 7, 4, 5, 5, 6, 7, 7, 6, 7, 7, 8, 9, 9, 10, 11, 11, 10, 11, 11, 12, 13, 13, 14, 15, 15, 14, 15, 15, 12, 13, 13, 14, 15, 15, 14, 15, 15, 8, 9, 9, 10, 11, 11, 10, 11, 11, 12, 13, 13, 14, 15, 15, 14, 15, 15, 12
OFFSET
0,4
COMMENTS
The ones in the binary representation of a(n) correspond to the nonzero digits in the ternary representation of n; for example: ternary(42) = 1120 and binary(a(42)) = 1110 (a(42) = 14).
Each number k >= 0 appears 2^A000120(k) times.
a(A004488(n)) = a(n).
LINKS
FORMULA
a(0) = 0.
a(3*n) = 2*a(n).
a(3*n + 1) = 2*a(n) + 1.
a(3*n + 2) = 2*a(n) + 1.
EXAMPLE
The first values, alongside the ternary representation of n, and the binary representation of a(n), are:
n a(n) ternary(n) binary(a(n))
-- ---- ---------- ------------
0 0 0 0
1 1 1 1
2 1 2 1
3 2 10 10
4 3 11 11
5 3 12 11
6 2 20 10
7 3 21 11
8 3 22 11
9 4 100 100
10 5 101 101
11 5 102 101
12 6 110 110
13 7 111 111
14 7 112 111
15 6 120 110
16 7 121 111
17 7 122 111
18 4 200 100
19 5 201 101
20 5 202 101
21 6 210 110
22 7 211 111
23 7 212 111
24 6 220 110
25 7 221 111
26 7 222 111
MATHEMATICA
Table[FromDigits[Sign@ IntegerDigits[n, 3], 2], {n, 0, 100}] (* Indranil Ghosh, Aug 03 2017 *)
PROG
(PARI) a(n) = my (d=digits(n, 3)); fromdigits(vector(#d, i, sign(d[i])), 2)
(Python)
from sympy.ntheory.factor_ import digits
from sympy import sign
def a(n):
d=digits(n, 3)[1:]
return int(''.join(str(sign(i)) for i in d), 2)
print([a(n) for n in range(101)]) # Indranil Ghosh, Aug 03 2017
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Jul 13 2017
STATUS
approved
Filter based on 2-digits of base-3 expansion: a(n) = A278222(A289814(n)).
+20
6
1, 1, 2, 1, 1, 2, 2, 2, 4, 1, 1, 2, 1, 1, 2, 2, 2, 4, 2, 2, 6, 2, 2, 6, 4, 4, 8, 1, 1, 2, 1, 1, 2, 2, 2, 4, 1, 1, 2, 1, 1, 2, 2, 2, 4, 2, 2, 6, 2, 2, 6, 4, 4, 8, 2, 2, 6, 2, 2, 6, 6, 6, 12, 2, 2, 6, 2, 2, 6, 6, 6, 12, 4, 4, 12, 4, 4, 12, 8, 8, 16, 1, 1, 2, 1, 1, 2, 2, 2, 4, 1, 1, 2, 1, 1, 2, 2, 2, 4, 2, 2, 6, 2, 2, 6, 4, 4, 8, 1, 1, 2, 1
OFFSET
0,3
LINKS
FORMULA
a(n) = A278222(A289814(n)).
PROG
(Scheme) (define (A290092 n) (A278222 (A289814 n)))
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Jul 25 2017
STATUS
approved
a(n) = Product_{d|A000265(n)} A019565(A289814(d)); a product obtained from the 2-digits present in ternary expansions of the odd divisors of n.
+20
5
1, 1, 1, 1, 2, 1, 3, 1, 1, 2, 2, 1, 1, 3, 6, 1, 6, 1, 5, 2, 15, 2, 10, 1, 30, 1, 1, 3, 2, 6, 1, 1, 6, 6, 36, 1, 1, 5, 1, 2, 2, 15, 3, 2, 30, 10, 10, 1, 15, 30, 90, 1, 30, 1, 28, 3, 35, 2, 14, 6, 21, 1, 105, 1, 28, 6, 7, 6, 210, 36, 42, 1, 35, 1, 3150, 5, 420, 1, 105, 2, 1, 2, 2, 15, 12, 3, 6, 2, 6, 30, 3, 10, 1, 10
OFFSET
1,5
FORMULA
a(n) = A351082(A000265(n)).
PROG
(PARI)
A019565(n) = { my(m=1, p=1); while(n>0, p = nextprime(1+p); if(n%2, m *= p); n >>= 1); (m); };
A289814(n) = { my(d=digits(n, 3)); fromdigits(vector(#d, i, if (d[i]==2, 1, 0)), 2); };
A351092(n) = { my(m=1); fordiv(n>>valuation(n, 2), d, m *= A019565(A289814(d))); (m); };
CROSSREFS
Cf. A000265, A019565, A289814, A351082, A351091, A351094 (rgs-transform).
KEYWORD
nonn,easy
AUTHOR
Antti Karttunen, Jan 31 2022
STATUS
approved
Multiplicative with a(p^e) = A019565(A289814(e)).
+20
4
1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 3, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 2, 1, 2, 2, 4, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1
OFFSET
1,4
PROG
(Scheme) (define (A294932 n) (if (= 1 n) n (* (A019565 (A289814 (A067029 n))) (A294932 (A028234 n)))))
CROSSREFS
KEYWORD
nonn,mult
AUTHOR
Antti Karttunen, Nov 11 2017
STATUS
approved
a(n) = Product_{d|n, d<n} A019565(A289814(A295882(d))); a product obtained from the -1's present in balanced ternary representation of the deficiencies of the proper divisors of n.
+20
4
1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 3, 2, 1, 1, 12, 1, 2, 6, 1, 1, 12, 1, 1, 12, 3, 1, 12, 1, 1, 2, 15, 3, 216, 1, 5, 2, 6, 1, 6, 1, 2, 36, 5, 1, 180, 3, 10, 30, 1, 1, 1080, 1, 3, 10, 1, 1, 3240, 1, 1, 36, 1, 1, 20, 1, 450, 10, 30, 1, 45360, 1, 1, 30, 75, 3, 10, 1, 60, 360, 1, 1, 540, 15, 105, 2, 2, 1, 3240, 3, 50, 2, 35, 5, 2520, 1, 630, 60, 90, 1, 900
OFFSET
1,6
COMMENTS
Used as a part of filter A296073.
LINKS
FORMULA
a(n) = Product_{d|n, d<n} A019565(A289814(A295882(d))).
PROG
(PARI)
A019565(n) = {my(j, v); factorback(Mat(vector(if(n, #n=vecextract(binary(n), "-1..1")), j, [prime(j), n[j]])~))}; \\ This function from M. F. Hasler
A117967(n) = if(n<=1, n, if(!(n%3), 3*A117967(n/3), if(1==(n%3), 1+3*A117967((n-1)/3), 2+3*A117967((n+1)/3))));
A117968(n) = if(1==n, 2, if(!(n%3), 3*A117968(n/3), if(1==(n%3), 2+3*A117968((n-1)/3), 1+3*A117968((n+1)/3))));
A289814(n) = { my (d=digits(n, 3)); from digits(vector(#d, i, if (d[i]==2, 1, 0)), 2); } \\ From Rémy Sigrist
A295882(n) = { my(x = (2*n)-sigma(n)); if(x >= 0, A117967(x), A117968(-x)); };
A296072(n) = { my(m=1); fordiv(n, d, if(d < n, m *= A019565(A289814(A295882(d))))); m; };
(Scheme)
(define (A296072 n) (let loop ((m 1) (props (proper-divisors n))) (cond ((null? props) m) (else (loop (* m (A019565 (A289814 (A295882 (car props))))) (cdr props))))))
(define (proper-divisors n) (reverse (cdr (reverse (divisors n)))))
(define (divisors n) (let loop ((k n) (divs (list))) (cond ((zero? k) divs) ((zero? (modulo n k)) (loop (- k 1) (cons k divs))) (else (loop (- k 1) divs)))))
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Dec 04 2017
STATUS
approved
a(n) = Product_{d|n} A019565(A289814(d)); a product obtained from the 2-digits present in ternary expansions of the divisors of n.
+20
3
1, 2, 1, 2, 2, 6, 3, 12, 1, 4, 2, 6, 1, 12, 6, 36, 6, 30, 5, 40, 15, 20, 10, 540, 30, 60, 1, 12, 2, 36, 1, 72, 6, 36, 36, 30, 1, 20, 1, 240, 2, 540, 3, 120, 30, 100, 10, 8100, 15, 600, 90, 900, 30, 210, 28, 1008, 35, 28, 14, 7560, 21, 84, 105, 504, 28, 1260, 7, 504, 210, 3024, 42, 94500, 35, 140, 3150, 700, 420, 18900
OFFSET
1,2
FORMULA
a(n) = A019565(A289814(n)) * A293222(n).
PROG
(PARI)
A019565(n) = { my(m=1, p=1); while(n>0, p = nextprime(1+p); if(n%2, m *= p); n >>= 1); (m); };
A289814(n) = { my(d=digits(n, 3)); fromdigits(vector(#d, i, if (d[i]==2, 1, 0)), 2); };
A351082(n) = { my(m=1); fordiv(n, d, m *= A019565(A289814(d))); (m); };
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Antti Karttunen, Jan 31 2022
STATUS
approved
Sum of digits of (n written in base 3).
+10
114
0, 1, 2, 1, 2, 3, 2, 3, 4, 1, 2, 3, 2, 3, 4, 3, 4, 5, 2, 3, 4, 3, 4, 5, 4, 5, 6, 1, 2, 3, 2, 3, 4, 3, 4, 5, 2, 3, 4, 3, 4, 5, 4, 5, 6, 3, 4, 5, 4, 5, 6, 5, 6, 7, 2, 3, 4, 3, 4, 5, 4, 5, 6, 3, 4, 5, 4, 5, 6, 5, 6, 7, 4, 5, 6, 5, 6, 7, 6, 7, 8, 1, 2, 3, 2, 3, 4, 3, 4, 5, 2, 3, 4, 3, 4, 5, 4, 5, 6, 3, 4, 5, 4, 5, 6
OFFSET
0,3
COMMENTS
Also the fixed point of the morphism 0->{0,1,2}, 1->{1,2,3}, 2->{2,3,4}, etc. - Robert G. Wilson v, Jul 27 2006
LINKS
F. T. Adams-Watters and F. Ruskey, Generating Functions for the Digital Sum and Other Digit Counting Sequences, JIS, Vol. 12 (2009), Article 09.5.6.
F. M. Dekking, The Thue-Morse Sequence in Base 3/2, J. Int. Seq., Vol. 26 (2023), Article 23.2.3.
A. V. Kitaev and A. Vartanian, Algebroid Solutions of the Degenerate Third Painlevé Equation for Vanishing Formal Monodromy Parameter, arXiv:2304.05671 [math.CA], 2023. See pp. 11, 13.
Jan-Christoph Puchta and Jürgen Spilker, Altes und Neues zur Quersumme, Math. Semesterber, Vol. 49 (2002), pp. 209-226; preprint.
Jeffrey O. Shallit, Problem 6450, Advanced Problems, The American Mathematical Monthly, Vol. 91, No. 1 (1984), pp. 59-60; Two series, solution to Problem 6450, ibid., Vol. 92, No. 7 (1985), pp. 513-514.
Vladimir Shevelev, Compact integers and factorials, Acta Arith., Vol. 126, No. 3 (2007), pp. 195-236 (cf. p.205).
Eric Weisstein's World of Mathematics, Digit Sum.
FORMULA
From Benoit Cloitre, Dec 19 2002: (Start)
a(0) = 0, a(3n) = a(n), a(3n + 1) = a(n) + 1, a(3n + 2) = a(n) + 2.
a(n) = n - 2*Sum_{k>0} floor(n/3^k) = n - 2*A054861(n). (End)
a(n) = A062756(n) + 2*A081603(n). - Reinhard Zumkeller, Mar 23 2003
G.f.: (Sum_{k >= 0} (x^(3^k) + 2*x^(2*3^k))/(1 + x^(3^k) + x^(2*3^k)))/(1 - x). - Michael Somos, Mar 06 2004, corrected by Franklin T. Adams-Watters, Nov 03 2005
In general, the sum of digits of (n written in base b) has generating function (Sum_{k>=0} (Sum_{0 <= i < b} i*x^(i*b^k))/(Sum_{i=0..b-1} x^(i*b^k)))/(1-x). - Franklin T. Adams-Watters, Nov 03 2005
First differences of A094345. - Vladeta Jovovic, Nov 08 2005
a(A062318(n)) = n and a(m) < n for m < A062318(n). - Reinhard Zumkeller, Feb 26 2008
a(n) = A138530(n,3) for n > 2. - Reinhard Zumkeller, Mar 26 2008
a(n) <= 2*log_3(n+1). - Vladimir Shevelev, Jun 01 2011
a(n) = Sum_{k>=0} A030341(n, k). - Philippe Deléham, Oct 21 2011
G.f. satisfies G(x) = (x+2*x^2)/(1-x^3) + (1+x+x^2)*G(x^3), and has a natural boundary at |x|=1. - Robert Israel, Jul 02 2015
a(n) = A056239(A006047(n)). - Antti Karttunen, Jun 03 2017
a(n) = A000120(A289813(n)) + 2*A000120(A289814(n)). - Antti Karttunen, Jul 20 2017
a(0) = 0; a(n) = a(n - 3^floor(log_3(n))) + 1. - Ilya Gutkovskiy, Aug 23 2019
Sum_{n>=1} a(n)/(n*(n+1)) = 3*log(3)/2 (Shallit, 1984). - Amiram Eldar, Jun 03 2021
EXAMPLE
a(20) = 2 + 0 + 2 = 4 because 20 is written as 202 base 3.
From Omar E. Pol, Feb 20 2010: (Start)
This can be written as a triangle with row lengths A025192 (see the example in the entry A000120):
0,
1,2,
1,2,3,2,3,4,
1,2,3,2,3,4,3,4,5,2,3,4,3,4,5,4,5,6,
1,2,3,2,3,4,3,4,5,2,3,4,3,4,5,4,5,6,3,4,5,4,5,6,5,6,7,2,3,4,3,4,5,4,5,6,3,...
where the k-th row contains a(3^k+i) for 0<=i<2*3^k and converges to A173523 as k->infinity. (End) [Changed conjectures to statements in this entry. - Franklin T. Adams-Watters, Jul 02 2015]
G.f. = x + 2*x^2 + x^3 + 2*x^4 + 3*x^5 + 2*x^6 + 3*x^7 + 4*x^8 + x^9 + 2*x^10 + ...
MAPLE
seq(convert(convert(n, base, 3), `+`), n=0..100); # Robert Israel, Jul 02 2015
MATHEMATICA
Table[Plus @@ IntegerDigits[n, 3], {n, 0, 100}] (* or *)
Nest[Join[#, # + 1, # + 2] &, {0}, 6] (* Robert G. Wilson v, Jul 27 2006 and modified Jul 27 2014 *)
PROG
(PARI) {a(n) = if( n<1, 0, a(n\3) + n%3)}; /* Michael Somos, Mar 06 2004 */
(PARI) A053735(n)=sumdigits(n, 3) \\ Requires version >= 2.7. Use sum(i=1, #n=digits(n, 3), n[i]) in older versions. - M. F. Hasler, Mar 15 2016
(Haskell)
a053735 = sum . a030341_row
-- Reinhard Zumkeller, Feb 21 2013, Feb 19 2012
(Scheme) (define (A053735 n) (let loop ((n n) (s 0)) (if (zero? n) s (let ((d (mod n 3))) (loop (/ (- n d) 3) (+ s d)))))) ;; For R6RS standard. Use modulo instead of mod in older Schemes like MIT/GNU Scheme. - Antti Karttunen, Jun 03 2017
(Magma) [&+Intseq(n, 3):n in [0..104]]; // Marius A. Burtea, Jan 17 2019
(MATLAB) m=1; for u=0:104; sol(m)=sum(dec2base(u, 3)-'0'); m=m+1; end
sol; % Marius A. Burtea, Jan 17 2019
CROSSREFS
Cf. A065363, A007089, A173523. See A134451 for iterations.
Sum of digits of n written in bases 2-16: A000120, this sequence, A053737, A053824, A053827, A053828, A053829, A053830, A007953, A053831, A053832, A053833, A053834, A053835, A053836.
Related base-3 sequences: A006047, A230641, A230642, A230643, A230853, A230854, A230855, A230856, A230639, A230640, A010063 (trajectory of 1), A286585, A286632, A289813, A289814.
KEYWORD
base,nonn,easy
AUTHOR
Henry Bottomley, Mar 28 2000
STATUS
approved
Tersum n + n.
+10
57
0, 2, 1, 6, 8, 7, 3, 5, 4, 18, 20, 19, 24, 26, 25, 21, 23, 22, 9, 11, 10, 15, 17, 16, 12, 14, 13, 54, 56, 55, 60, 62, 61, 57, 59, 58, 72, 74, 73, 78, 80, 79, 75, 77, 76, 63, 65, 64, 69, 71, 70, 66, 68, 67, 27, 29, 28, 33, 35, 34, 30, 32, 31, 45, 47, 46, 51
OFFSET
0,2
COMMENTS
Could also be described as "Write n in base 3, then replace each digit with its base-3 negative" as with A048647 for base 4. - Henry Bottomley, Apr 19 2000
a(a(n)) = n, a self-inverse permutation of the nonnegative integers. - Reinhard Zumkeller, Dec 19 2003
First 3^n terms of the sequence form a permutation s(n) of 0..3^n-1, n>=1; the number of inversions of s(n) is A016142(n-1). - Gheorghe Coserea, Apr 23 2018
FORMULA
Tersum m + n: write m and n in base 3 and add mod 3 with no carries, e.g., 5 + 8 = "21" + "22" = "10" = 1.
a(n) = Sum(3-d(i)-3*0^d(i): n=Sum(d(i)*3^d(i): 0<=d(i)<3)). - Reinhard Zumkeller, Dec 19 2003
a(3*n) = 3*a(n), a(3*n+1) = 3*a(n)+2, a(3*n+2) = 3*a(n)+1. - Robert Israel, May 09 2014
MAPLE
a:= proc(n) local t, r, i;
t, r:= n, 0;
for i from 0 while t>0 do
r:= r+3^i *irem(2*irem(t, 3, 't'), 3)
od; r
end:
seq(a(n), n=0..80); # Alois P. Heinz, Sep 07 2011
MATHEMATICA
a[n_] := FromDigits[Mod[3-IntegerDigits[n, 3], 3], 3]; Table[a[n], {n, 0, 66}] (* Jean-François Alcover, Mar 03 2014 *)
PROG
(Haskell)
a004488 0 = 0
a004488 n = if d == 0 then 3 * a004488 n' else 3 * a004488 n' + 3 - d
where (n', d) = divMod n 3
-- Reinhard Zumkeller, Mar 12 2014
(PARI) a(n) = my(b=3); fromdigits(apply(d->(b-d)%b, digits(n, b)), b);
vector(67, i, a(i-1)) \\ Gheorghe Coserea, Apr 23 2018
(Python)
from sympy.ntheory.factor_ import digits
def a(n): return int("".join([str((3 - i)%3) for i in digits(n, 3)[1:]]), 3) # Indranil Ghosh, Jun 06 2017
CROSSREFS
Column k=0 of A253586, A253587.
Column k=3 of A248813.
Row / column 2 of A325820.
Main diagonal of A004489.
KEYWORD
nonn,base,look
STATUS
approved
Balanced ternary enumeration (based on balanced ternary representation) of integers; write n in ternary and then replace 2's with (-1)'s.
+10
48
0, 1, -1, 3, 4, 2, -3, -2, -4, 9, 10, 8, 12, 13, 11, 6, 7, 5, -9, -8, -10, -6, -5, -7, -12, -11, -13, 27, 28, 26, 30, 31, 29, 24, 25, 23, 36, 37, 35, 39, 40, 38, 33, 34, 32, 18, 19, 17, 21, 22, 20, 15, 16, 14, -27, -26, -28, -24, -23, -25, -30, -29, -31, -18, -17, -19, -15, -14, -16, -21, -20, -22, -36
OFFSET
0,4
COMMENTS
As the graph demonstrates, there are large discontinuities in the sequence between terms 3^i-1 and 3^i, and between terms 2*3^i-1 and 2*3^i. - N. J. A. Sloane, Jul 03 2016
REFERENCES
D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, Vol. 2, pp. 173-175; 2nd. ed. pp. 190-193.
LINKS
Gheorghe Coserea, Table of n, a(n) for n = 0..59048 (first 729 terms from A. Karttunen)
N. J. A. Sloane and Brady Haran, Amazing Graphs II (including Star Wars), Numberphile video (2019)
Wikipedia, Balanced ternary
FORMULA
a(0) = 0, a(3n) = 3a(n), a(3n+1) = 3a(n)+1, a(3n+2) = 3a(n)-1.
G.f. satisfies A(x) = 3*A(x^3)*(1+x+x^2) + x/(1+x+x^2). - corrected by Robert Israel, Nov 17 2015
A004488(n) = a(n)^{-1}(-a(n)). I.e., if a(n) <= 0, A004488(n) = A117967(-a(n)) and if a(n) > 0, A004488(n) = A117968(a(n)).
a(n) = n - 3 * A005836(A289814(n) + 1). - Andrey Zabolotskiy, Nov 11 2019
EXAMPLE
7 in base 3 is 21; changing the 2 to a (-1) gives (-1)*3+1 = -2, so a(7) = -2. I.e., the number of -2 according to the balanced ternary enumeration is 7, which can be obtained by replacing every -1 by 2 in the balanced ternary representation (or expansion) of -2, which is -1,1.
MAPLE
f:= proc(n) local L, i;
L:= subs(2=-1, convert(n, base, 3));
add(L[i]*3^(i-1), i=1..nops(L))
end proc:
map(f, [$0..100]);
# alternate:
N:= 100: # to get a(0) to a(N)
g:= 0:
for n from 1 to ceil(log[3](N+1)) do
g:= convert(series(3*subs(x=x^3, g)*(1+x+x^2)+x/(1+x+x^2), x, 3^n+1), polynom);
od:
seq(coeff(g, x, j), j=0..N); # Robert Israel, Nov 17 2015
# third Maple program:
a:= proc(n) option remember; `if`(n=0, 0,
3*a(iquo(n, 3, 'r'))+`if`(r=2, -1, r))
end:
seq(a(n), n=0..3^4-1); # Alois P. Heinz, Aug 14 2019
MATHEMATICA
Map[FromDigits[#, 3] &, IntegerDigits[#, 3] /. 2 -> -1 & /@ Range@ 80] (* Michael De Vlieger, Nov 17 2015 *)
PROG
(MIT/GNU Scheme:) (define (A117966 n) (let loop ((z 0) (i 0) (n n)) (if (zero? n) z (loop (+ z (* (expt 3 i) (if (= 2 (modulo n 3)) -1 (modulo n 3)))) (1+ i) (floor->exact (/ n 3)))))) -- Antti Karttunen, May 19 2008
(PARI) a(n) = subst(Pol(apply(x->if(x == 2, -1, x), digits(n, 3)), 'x), 'x, 3)
vector(73, i, a(i-1)) \\ Gheorghe Coserea, Nov 17 2015
(Python)
def a(n):
if n==0: return 0
if n%3==0: return 3*a(n//3)
elif n%3==1: return 3*a((n - 1)//3) + 1
else: return 3*a((n - 2)//3) - 1
print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 06 2017
KEYWORD
base,sign,look
AUTHOR
EXTENSIONS
Name corrected by Andrey Zabolotskiy, Nov 10 2019
STATUS
approved

Search completed in 0.021 seconds