login
Search: a004754 -id:a004754
     Sort: relevance | references | number | modified | created      Format: long | short | data
a(n) = A292272(A004754(n)) - 2*A053644(n).
+20
10
0, 0, 0, 1, 0, 1, 2, 2, 0, 1, 2, 2, 4, 5, 4, 4, 0, 1, 2, 2, 4, 5, 4, 4, 8, 9, 10, 10, 8, 9, 8, 8, 0, 1, 2, 2, 4, 5, 4, 4, 8, 9, 10, 10, 8, 9, 8, 8, 16, 17, 18, 18, 20, 21, 20, 20, 16, 17, 18, 18, 16, 17, 16, 16, 0, 1, 2, 2, 4, 5, 4, 4, 8, 9, 10, 10, 8, 9, 8, 8, 16, 17, 18, 18, 20, 21, 20, 20, 16, 17, 18, 18, 16, 17, 16, 16, 32, 33, 34, 34, 36, 37, 36, 36
OFFSET
0,7
COMMENTS
In binary expansion (A007088) of n, clear the most significant bit and all those 1-bits that have another 1-bit at their left side, except for the second most significant 1-bit, even in cases where the binary expansion begins as "11...".
Because A292943(n) = a(A243071(n)), the sequence works as a "masking function" where the 1-bits in a(n) (always a subset of the 1-bits in binary expansion of n) indicate which numbers are of the form 6k+3 (odd multiples of three) in binary tree A163511 (or its mirror image tree A005940) on that trajectory which leads from the root of the tree to the node containing A163511(n).
FORMULA
a(n) = A292272(A004754(n)) - 2*A053644(n).
a(n) = A292943(A163511(n)).
Other identities. For all n >= 0:
a(n) + A292264(n) = A292942(n) + a(n) + A292946(n) = a(n) + A292254(n) + A292256(n) = n.
a(n) = a(n) AND n; a(n) AND A292264(n) = 0, where AND is bitwise-and (A004198).
EXAMPLE
For n = 23, 10111 in binary, when we clear (change to zero) the most significant bit (always 1) and also all 1-bits that have 1's at their left side, we are left with 100, which in binary stands for 4, thus a(23) = 4.
For n = 27, 11011 in binary, when we clear the most significant bit, and also all 1-bits that have 1's at their left side except the second most significant, we are left with 1010, which in binary stands for ten, thus a(27) = 10.
PROG
(Scheme)
(define (A292944 n) (let ((x (+ n (A053644 n)))) (- (A292272 x) (A053644 x))))
(define (A292944 n) (- (A292272 (A004754 n)) (* 2 (A053644 n))))
(define (A292944 n) (A292943 (A163511 n)))
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, Sep 28 2017
STATUS
approved
Dispersion of A004754, a rectangular array T(n,k) read by downward antidiagonals.
+20
2
1, 2, 3, 4, 5, 6, 8, 9, 10, 7, 16, 17, 18, 11, 12, 32, 33, 34, 19, 20, 13, 64, 65, 66, 35, 36, 21, 14, 128, 129, 130, 67, 68, 37, 22, 15, 256, 257, 258, 131, 132, 69, 38, 23, 24, 512, 513, 514, 259, 260, 133, 70, 39, 40, 25, 1024, 1025, 1026, 515, 516, 261, 134
OFFSET
1,2
COMMENTS
As a sequence, {a(n)} permutes the positive integers. As an array, {T(n,k)} is an interspersion-dispersion or I-D array (refer to Kimberling, 1st linked reference).
The top row of {T(n,k)} is A000079 or powers of two = 1, 2, 4, 8, 16, ....
Except for the leftmost element "1" of the top row, rows of T(n,k) indexed n = 0, 1, 2, ..., consist entirely of even numbers (A005843) for n even and entirely of odd numbers (A005408) for n odd.
The left column (k = 1) of {T(n,k)} comprises a "1" for the top row (n = 0) and A004755(n) = n + 2^(floor(log_2(n)) + 1), for rows n = 1, 2, 3, ....
For rows indexed n = 0, 1, 2, ..., and columns indexed k = 1, 2, 3, ..., T(n,k) is given by T(0,k) = L^(k - 1)(1) and T(n,k) = L^(k - 1) R(n) for n = 1, 2, 3, ..., the image of n under a composition of branching functions L(n) = A004754(n) = n + 2^floor(log_2(n)) and R(n) = A004755(n) = n + 2^(floor(log_2(n)) + 1) (cf. generating tree A059893 and 2nd linked reference).
(Duality with array A054582): Consider A059893 and A000027 as labeled binary trees arranging the positive integers. In latter tree, node labels equal node positions, thus following their natural order. Rows of {T(n,k)} are the labels along maximal straight paths that always branch left in the former tree, while rows of (transposed) array A054582 are the labels along maximal straight paths that always branch left in the latter tree.
Column k of {T(n,k)} comprises the (sorted) labels in the k-th right clade of latter tree, while column k of (transposed) A054582 comprises the (sorted) labels in the k-th right clade of the former tree. This makes the arrays {T(n,k)} and (transposed) A054582 "blade-duals," blade being a contraction of branch-clade ('right clades' explained under tree A345253 and in 2nd link).
Write the positive integers in natural order as a (left-justified) "tetrangle" or "irregular triangle" tableau with 2^t entries on each row t, for t=1, 2, 3, .... Then, columns of the tableau equal rows of {T(n,k)} (2nd link):
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, 28, 29, 30, 31,
...
Analogous to A345252, its right-justified tableau of the positive integers in cohorts with lengths the Fibonacci numbers replaced by the above left-justified tableau with powers of two as lengths of the cohorts.
(Mirror duality): A "mirror dual" I-D array or "inverse I-D array" (see Kimberling, 1st linked reference) is obtained by substituting the left-justified tableau by a right-justified tableau and following the identical procedure, or equivalently by mirroring the tree A059893 cited above, i.e., taking maximal straight paths that always branch right in the tree A059893. With two types of duality then, {T(n,k)} forms a quartet of I-D arrays together with its mirror dual, its blade dual (transposed) A054582 and mirror dual A191448 of the latter.
(Para-sequences): Sequences of row and column indices (see Conway-Sloane correspondence under A019586, citing Kimberling). For rows indexed n = 0, 1, 2, ..., and columns indexed k = 1, 2, 3, ..., the row index n of positive integer T(n,k) is A053645(T) and the column index k of positive integer T(n,k) is A065120(T).
FORMULA
T(0,k) = 2^(k - 1) and T(n,k) = n + 2^(floor(log_2(n)) + k) for n >= 1.
T(0,k) = L^(k - 1)(1) and T(n,k) = L^(k - 1) R(n) for n = 1, 2, 3, ..., where L(n) = A004754(n) = n + 2^floor(log_2(n)) and R(n) = A004755(n) = n + 2^(floor(log_2(n)) + 1).
Let b(n) = A054582(n-1). Then for all n >= 1, a(n) = A139706(b(n)) and b(n) = A139708(a(n)).
EXAMPLE
Northwest corner of {T(n,k)}:
k=1 k=2 k=3 k=4 k=5 k=6
n=0: 1, 2, 4, 8, 16, 32, ...
n=1: 3, 5, 9, 17, 33, 65, ...
n=2: 6, 10, 18, 34, 66, 130, ...
n=3: 7, 11, 19, 35, 67, 131, ...
n=4: 12, 20, 36, 68, 132, 260, ...
...
Northwest corner of {T(n,k)} in base-2:
k=1 k=2 k=3 k=4 k=5 k=6
n=0: 1, 10, 100, 1000, 10000, 100000, ...
n=1: 11, 101, 1001, 10001, 100001, 1000001, ...
n=2: 110, 1010, 10010, 100010, 1000010, 10000010, ...
n=3: 111, 1011, 10011, 100010, 1000011, 10000011, ...
n=4: 1100,10100, 100100, 1000100, 10000100, 100000100, ...
...
MATHEMATICA
(*Simplified Formula*)
MatrixForm[Prepend[Table[n + 2^(Floor[Log[2, n]] + k), {n, 1, 4}, {k, 1, 6}], Table[2^(k - 1), {k, 1, 6}]]]
(*Branching Formula*)
MatrixForm[Prepend[Table[NestList[Function[# + 2^(Floor[Log[2, #]])], n + 2^(Floor[Log[2, n]] + 1), 5], {n, 1, 4}], NestList[Function[# + 2^(Floor[Log[2, #]])], 1, 5]]]
PROG
(PARI) T(n, k) = if (n==0, 2^(k-1), n + 2^(log(n)\log(2) + k));
matrix(7, 7, n, k, n--; T(n, k)) \\ Michel Marcus, Jul 30 2021
KEYWORD
nonn,tabl,easy
AUTHOR
J. Parker Shectman, Jun 12 2021
STATUS
approved
Binary expansion starts 11.
+10
24
3, 6, 7, 12, 13, 14, 15, 24, 25, 26, 27, 28, 29, 30, 31, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122
OFFSET
1,1
COMMENTS
a(n) is the smallest value > a(n-1) (or > 1 for n=1) for which A001511(a(n)) = A001511(n). - Franklin T. Adams-Watters, Oct 23 2006
LINKS
Kenny Lau, Table of n, a(n) for n = 1..16383 (first 1023 terms from T. D. Noe)
FORMULA
a(2n) = 2*a(n), a(2n+1) = 2*a(n) + 1 + 2*[n==0].
a(n) = n + 2 * 2^floor(log_2(n)) = A004754(n) + A053644(n).
a(n) = 2n + A080079(n). - Benoit Cloitre, Feb 22 2003
G.f.: (1/(1+x)) * (1 + Sum_{k>=0, t=x^2^k} 2^k*(2t+t^2)/(1+t)).
a(n) = n + 2^(floor(log_2(n)) + 1) = n + A062383(n). - Franklin T. Adams-Watters, Oct 23 2006
a(2^m+k) = 2^(m+1) + 2^m + k, m >= 0, 0 <= k < 2^m. - Yosu Yurramendi, Aug 08 2016
EXAMPLE
12 in binary is 1100, so 12 is in the sequence.
MAPLE
a:= proc(n) n+2*2^floor(log(n)/log(2)) end: seq(a(n), n=1..60); # Muniru A Asiru, Oct 16 2018
MATHEMATICA
Flatten[Table[FromDigits[#, 2]&/@(Join[{1, 1}, #]&/@Tuples[{0, 1}, n]), {n, 0, 5}]] (* Harvey P. Dale, Feb 05 2015 *)
PROG
(PARI) a(n)=n+2*2^floor(log(n)/log(2))
(PARI) is(n)=n>2 && binary(n)[2] \\ Charles R Greathouse IV, Sep 23 2012
(Haskell)
import Data.List (transpose)
a004755 n = a004755_list !! (n-1)
a004755_list = 3 : concat (transpose [zs, map (+ 1) zs])
where zs = map (* 2) a004755_list
-- Reinhard Zumkeller, Dec 04 2015
(Python)
f = open('b004755.txt', 'w')
lo = 3
hi = 4
i = 1
while i<16384:
for x in range(lo, hi):
f.write(str(i)+" "+str(x)+"\n")
i += 1
lo <<= 1
hi <<= 1
# Kenny Lau, Jul 05 2016
(Python)
def A004755(n): return n+(1<<n.bit_length()) # Chai Wah Wu, Jul 13 2022
CROSSREFS
Equals union of A079946 and A080565.
Cf. A004754 (10), A004756 (100), A004757 (101), A004758 (110), A004759 (111).
KEYWORD
nonn,base,easy
EXTENSIONS
Edited by Ralf Stephan, Oct 12 2003
STATUS
approved
Number of 1's in 2's complement representation of -n.
+10
17
0, 1, 1, 2, 1, 3, 2, 2, 1, 4, 3, 3, 2, 3, 2, 2, 1, 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, 7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3
OFFSET
0,4
COMMENTS
a(A127904(n)) = n and a(m) < n for m < A127904(n). - Reinhard Zumkeller, Feb 05 2007
a(n) = A000120(A010078(n)), n>0; a(n) = A023416(A004754(n-1)), n>1. - Reinhard Zumkeller, Dec 04 2015
Conjecture: a(n)+1 is the length of the Hirzebruch (negative) continued fraction for the Stern-Brocot tree fraction A007305(n)/A007306(n). - Andrey Zabolotskiy, Apr 17 2020
Terms a(n); n >= 2 can be generated recursively, as follows. Let S(0) = {1}, then for k >=1, let S(k) = {S(k-1)+1, S(k-1)}, where +1 means +1 on every term of S(k-1); see Example. Each step of the recursion gives the next 2^k terms of the sequence. - David James Sycamore, Jul 15 2024
LINKS
FORMULA
a(n) = A023416(n-1) + 1.
a(n) = if n<=1 then n else (n mod 2) + a((n mod 2) + floor(n/2)). - Reinhard Zumkeller, Feb 05 2007
a(n) = if n<2 then n else a(ceiling(n/2)) + n mod 2. - Reinhard Zumkeller, Jul 25 2006
Min{m: a(m)=n} = if n>0 then A083318(n-1) else 0. - Reinhard Zumkeller, Jul 25 2006
EXAMPLE
Using the above recursion for a(n); n >= 2, we have:
S(0) = {1} so a(2) = 1;
S(1) = {2,1} so a(3,4) = 2,1;
S(2) = {3,2,2,1}, so a(5,6,7,8) = 3,2,2,1;
As irregular table the sequence for n >= 2 begins:
1;
2,1;
3,2,2,1;
4,3,3,2,3,2,2,1;
5,4,4,3,4,3,3,2,4,3,3,2,3,2,2,1;
6,5,5,4,5,4,4,3,5,4,3,3,4,3,3,2,5,4,4,3,4,3,3,2,4,3,3,2,3,2,2,1;
and so on (the k-th row contains 2^k terms; k>=0). - David James Sycamore, Jul 15 2024
MATHEMATICA
a[0] = 0; a[1] = 1; a[n_] := a[n] = Mod[n, 2] + a[Mod[n, 2] + Floor[n/2]]; Array[a, 96, 0] (* Jean-François Alcover, Aug 12 2017, after Reinhard Zumkeller *)
PROG
(Haskell)
a008687 n = a008687_list !! n
a008687_list = 0 : 1 : c [1] where c (e:es) = e : c (es ++ [e+1, e])
-- Reinhard Zumkeller, Mar 07 2011
(PARI) a(n) = if(n<2, n, n--; logint(n, 2) - hammingweight(n) + 2); \\ Kevin Ryde, Apr 14 2021
CROSSREFS
This is Guy Steele's sequence GS(4, 3) (see A135416).
KEYWORD
nonn,base
AUTHOR
STATUS
approved
Number of leading 1's in binary expansion of n.
+10
15
0, 1, 1, 2, 1, 1, 2, 3, 1, 1, 1, 1, 2, 2, 3, 4, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2
OFFSET
0,4
COMMENTS
Mirror of triangle A065120. See example. - Omar E. Pol, Oct 17 2013
a(n) is also the least part in the integer partition having viabin number n. The viabin number of an integer partition is defined in the following way. Consider the southeast border of the Ferrers board of the integer partition and consider the binary number obtained by replacing each east step with 1 and each north step, except the last one, with 0. The corresponding decimal form is, by definition, the viabin number of the given integer partition. "Viabin" is coined from "via binary". For example, consider the integer partition [2,2,2,1]. The southeast border of its Ferrers board yields 10100, leading to the viabin number 20. - Emeric Deutsch, Jul 24 2017
LINKS
Alois P. Heinz, Table of n, a(n) for n = 0..65535 (first 10001 terms from Vincenzo Librandi)
FORMULA
a(2^k-1)=k; a(A004754(k))=1; a(A004758(k))=2.
a(2^k-1)=k; for any other n, a(n) = a(floor(n/2)).
a(n) = f(n, 0) with f(n, x) = if n < 2 then n + x else f([n/2], (x+1)*(n mod 2)). - Reinhard Zumkeller, Feb 02 2007
Conjecture: a(n) = w(n+1)*(w(n+1)-w(n)+1) - w(2^(w(n+1)+1)-n-1) for n>0, where w(n) = floor(log_2(n)), that is, A000523(n). - Velin Yanev, Dec 21 2016
a(n) = A360189(n-1,floor(log_2(n))). - Alois P. Heinz, Mar 06 2023
EXAMPLE
In binary : 14=1110 and there are 3 leading 1's, so a(14)=3.
From Omar E. Pol, Oct 17 2013: (Start)
Written as an irregular triangle with row lengths A011782 the sequence begins:
0;
1;
1,2;
1,1,2,3;
1,1,1,1,2,2,3,4;
1,1,1,1,1,1,1,1,2,2,2,2,3,3,4,5;
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,4,4,5,6;
Right border gives A001477. Row sums give A000225.
(End)
MAPLE
a := proc(n) if type(log[2](n+1), integer) then log[2](n+1) else a(floor((1/2)*n)) end if end proc: seq(a(n), n = 0 .. 200); # Emeric Deutsch, Jul 24 2017
# second Maple program:
b:= proc(n, t) `if`(n=0, t,
b(iquo(n, 2, 'm'), m*(t+1)))
end:
a:= n-> b(n, 0):
seq(a(n), n=0..127); # Alois P. Heinz, Mar 06 2023
MATHEMATICA
Join[{0}, Table[Length@First@Split@IntegerDigits[n, 2], {n, 30}]] (* Birkas Gyorgy, Mar 09 2011 *) (* adapted by Vincenzo Librandi, Dec 23 2016 *)
PROG
(PARI) a(n) = if(n==0, 0); b=binary(n+1); if(hammingweight(b) == 1, #b-1, a(n\2)) \\ David A. Corneth, Jul 24 2017
(PARI) a(n) = if(n==0, 0); my(b = binary(n), r = #b); for(i=2, #b, if(!b[i], return(i-1))); r \\ David A. Corneth, Jul 24 2017
CROSSREFS
a(n) = A007814(1+A030101(n)).
KEYWORD
nonn,base
AUTHOR
Benoit Cloitre, Feb 29 2004
EXTENSIONS
Edited and corrected by Franklin T. Adams-Watters, Apr 08 2006
Sequence had accidentally been shifted left by one step, which was corrected and term a(0)=0 added by Antti Karttunen, Jan 01 2007
STATUS
approved
a(1) = 0, a(2) = 1, and for n > 2, a(n) = 2*a(A252463(n)) + [n == 1 (mod 4)].
+10
15
0, 1, 2, 2, 5, 4, 10, 4, 5, 10, 20, 8, 41, 20, 8, 8, 83, 10, 166, 20, 21, 40, 332, 16, 11, 82, 8, 40, 665, 16, 1330, 16, 41, 166, 16, 20, 2661, 332, 80, 40, 5323, 42, 10646, 80, 17, 664, 21292, 32, 23, 22, 164, 164, 42585, 16, 42, 80, 333, 1330, 85170, 32, 170341, 2660, 40, 32, 83, 82, 340682, 332, 665, 32, 681364, 40, 1362729, 5322, 20, 664, 33, 160
OFFSET
1,3
COMMENTS
Variant of A292381. Here the most significant 1-bit is at the one step smaller position.
FORMULA
a(1) = 0, a(2) = 1, and for n > 2, a(n) = 2*a(A252463(n)) + [n == 1 (mod 4)], where the last part of the formula is Iverson bracket, giving 1 only if n is of the form 4k+1, and 0 otherwise.
For n >= 1, a(n) + A292383(n) = A243071(n); a(A163511(n)) = A292271(n).
For n >= 2, A004754(a(n)) = A292381(n).
PROG
(Scheme, with memoization-macro definec)
(definec (A292385 n) (if (<= n 2) (- n 1) (+ (if (= 1 (modulo n 4)) 1 0) (* 2 (A292385 (A252463 n))))))
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, Sep 16 2017
STATUS
approved
Tabular arrangement of the natural numbers: the row on which any nonzero term a(n) appears in is A053645(a(n))=A053645(n+1), and the column is A161511(a(n)). Table is presented by columns with 2^{k-1} items in column k, unused positions are filled with 0's.
+10
12
1, 2, 3, 4, 5, 0, 7, 8, 9, 6, 11, 0, 0, 0, 15, 16, 17, 10, 19, 0, 13, 0, 23, 0, 0, 0, 0, 0, 0, 0, 31, 32, 33, 18, 35, 12, 21, 14, 39, 0, 0, 0, 27, 0, 0, 0, 47, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 63, 64, 65, 34, 67, 20, 37, 22, 71, 0, 25, 0, 43, 0, 29, 0, 79, 0, 0, 0, 0, 0, 0, 0, 55, 0, 0
OFFSET
0,2
COMMENTS
Note: 1 might be a more natural starting offset for this sequence, although the identities concerning A053645 and A161511 would have to be changed. - Antti Karttunen, Oct 12 2009.
This can be regarded as an arrangement of the partitions, indexed by position in A125106. The partitions in a given row all have the same remaining partition when the largest part is removed; specifically, the partition indexed by the row number in A125106 (with row 0 having the empty partition remaining).
The first value on row n is A004760(n+1). The second value on each row is A004760(n+1) plus A062383(n); subsequent values increase by ever enlarging powers of two. Or equivalently, each subsequent value on the row after the first nonzero value is given by A004754(previous value on the same row).
A055941(r) tells how many terms the row r (>= 0) has been shifted rightward from its "natural position", i.e. with how many zeros that row has been prepended.
The number of (nonzero) entries in column k is A000041(k).
EXAMPLE
The largest power of 2 <= 6 is 4, 6 - 4 = 2, so 6 is in row 2. By A125106, 6 corresponds to the partition [2^2], total 4, so 6 goes in column 4. Thus T(2,4) = 6.
The table begins:
1.2.4..8.16.32.64.128.256.512.1024
..3.5..9.17.33.65.129.257.513.1025
.......6.10.18.34..66.130.258..514
....7.11.19.35.67.131.259.515.1027
............12.20..36..68.132..260
.........13.21.37..69.133.261..517
............14.22..38..70.134..262
......15.23.39.71.135.263.519.1031
...................24..40..72..136
...............25..41..73.137..265
...................26..42..74..138
............27.43..75.139.267..523
.......................28..44...76
...............29..45..77.141..269
...................30..46..78..142
.........31.47.79.143.271.527.1039
...........................48...80
.......................49..81..145
...........................50...82
...................51..83.147..275
MATHEMATICA
columns = 7; row[n_] := n-2^Floor[Log2[n]]; col[0] = 0; col[n_] := If[EvenQ[n], col[n/2] + DigitCount[n/2, 2, 1], col[(n-1)/2]+1]; Clear[T]; T[_, _] = 0; Do[T[row[k], col[k]] = k, {k, 1, 2^columns}]; Table[T[n-1, k], {k, 1, columns}, {n, 1, 2^(k-1)}] // Flatten (* Jean-François Alcover, Sep 09 2017 *)
PROG
(MIT/GNU Scheme)
(define (A126441 n) (A126441onebased (1+ n)))
(definec (A126441onebased n) (cond ((< n 2) n) (else (let ((prev (A126441onebased (- n (/ (A053644 n) 2))))) (if (or (= (A053644 n) (* 2 (A053644 (A053645 n)))) (zero? prev)) (let ((starter (A004760 (1+ (A053645 n))))) (if (> (A161511 starter) (1+ (A000523 n))) 0 starter)) (A004754 prev))))))
CROSSREFS
Cf. A125106, A053645, A000041, A004760, A062383, A000079 (column lengths).
A053645(a(A166274(n))) = A053645(1+A166274(n)) for all n>=1.
Positions of zeros: A166275, this sequence without zeros: A161924. A161920(n) gives the position of the first nonzero term on the row n-1.
KEYWORD
nonn,tabf
AUTHOR
Alford Arnold, Jan 19 2007
EXTENSIONS
Edited by Franklin T. Adams-Watters, Jan 23 2007
Further edited and Scheme-code added by Antti Karttunen, Oct 12 2009
STATUS
approved
Base-2 expansion of a(n) encodes the steps where numbers of the form 4k+1 are encountered when map x -> A252463(x) is iterated down to 1, starting from x=n.
+10
12
1, 2, 4, 4, 9, 8, 18, 8, 9, 18, 36, 16, 73, 36, 16, 16, 147, 18, 294, 36, 37, 72, 588, 32, 19, 146, 16, 72, 1177, 32, 2354, 32, 73, 294, 32, 36, 4709, 588, 144, 72, 9419, 74, 18838, 144, 33, 1176, 37676, 64, 39, 38, 292, 292, 75353, 32, 74, 144, 589, 2354, 150706, 64, 301413, 4708, 72, 64, 147, 146, 602826, 588, 1177, 64, 1205652, 72, 2411305, 9418, 36, 1176
OFFSET
1,2
FORMULA
a(1) = 1; for n > 1, a(n) = 2*a(A252463(n)) + [n ≡ 1 (mod 4)], where the last part of the formula is Iverson bracket, giving 1 only if n is of the form 4k+1, and 0 otherwise.
a(n) = A292371(A292384(n)).
Other identities. For n >= 1:
a(2n) = 2*a(n).
A000120(a(n)) = A292375(n).
For n >= 2, a(n) = A004754(A292385(n)).
EXAMPLE
For n = 1, the starting value (which is also the ending point) is of the form 4k+1, thus a(1) = 1*(2^0) = 1.
For n = 2, the starting value is not of the form 4k+1, but its parent, A252463(2) = 1 is, thus a(2) = 0*(2^0) + 1*(2^1) = 2.
For n = 3, the starting value is not of the form 4k+1, after which follows 2 (also not 4k+1), and then 2 -> 1, and it is only the end-point of iteration which is of the form 4k+1, thus a(3) = 0*(2^0) + 0*(2^1) + 1*(2^2) = 4.
For n = 5, the starting value is of the form 4k+1, after which follows A252463(5) = 3 (which is not), and then continuing as before as 3 -> 2 -> 1, thus a(5) = 1*(2^0) + 0*(2^1) + 0*(2^2) + 1*(2^3) = 9.
MATHEMATICA
Table[FromDigits[Reverse@ NestWhileList[Function[k, Which[k == 1, 1, EvenQ@ k, k/2, True, Times @@ Power[Which[# == 1, 1, # == 2, 1, True, NextPrime[#, -1]] & /@ First@ #, Last@ #] &@ Transpose@ FactorInteger@ k]], n, # > 1 &] /. k_ /; IntegerQ@ k :> If[Mod[k, 4] == 1, 1, 0], 2], {n, 76}] (* Michael De Vlieger, Sep 21 2017 *)
PROG
(PARI)
A064989(n) = {my(f); f = factor(n); if((n>1 && f[1, 1]==2), f[1, 2] = 0); for (i=1, #f~, f[i, 1] = precprime(f[i, 1]-1)); factorback(f)};
A252463(n) = if(!(n%2), n/2, A064989(n));
A292381(n) = if(1==n, n, (if(1==(n%4), 1, 0)+(2*A292381(A252463(n)))));
(Scheme) (define (A292381 n) (A292371 (A292384 n)))
(Python)
from sympy.core.cache import cacheit
from sympy.ntheory.factor_ import digits
from sympy import factorint, prevprime
from operator import mul
from functools import reduce
def a292371(n):
k=digits(n, 4)[1:]
return 0 if n==0 else int("".join(['1' if i==1 else '0' for i in k]), 2)
def a064989(n):
f=factorint(n)
return 1 if n==1 else reduce(mul, [1 if i==2 else prevprime(i)**f[i] for i in f])
def a252463(n): return 1 if n==1 else n//2 if n%2==0 else a064989(n)
@cacheit
def a292384(n): return 1 if n==1 else 4*a292384(a252463(n)) + n%4
def a(n): return a292371(a292384(n))
print([a(n) for n in range(1, 111)]) # Indranil Ghosh, Sep 21 2017
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, Sep 15 2017
STATUS
approved
Binary expansion starts 101.
+10
10
5, 10, 11, 20, 21, 22, 23, 40, 41, 42, 43, 44, 45, 46, 47, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185
OFFSET
1,1
LINKS
FORMULA
a(2n) = 2a(n), a(2n+1) = 2a(n) + 1 + 4*[n==0].
a(n) = n + 4 * 2^floor(log_2(n)) = A004756(n) + A053644(n).
a(2^m+k) = 5*2^m + k, m >= 0, 0 <= k < 2^m. - Yosu Yurramendi, Aug 08 2016
EXAMPLE
22 in binary is 10110, so 22 is in sequence.
MATHEMATICA
Table[n + 4*2^Floor@ Log2@ n, {n, 57}] (* or *)
w = {1, 0, 1}; Select[Range[5, 185], If[# < 2^(Length@ w - 1), True, Take[IntegerDigits[#, 2], Length@ w] == w] &] (* Michael De Vlieger, Aug 10 2016 *)
Select[Range[5, 200], Take[IntegerDigits[#, 2], 3]=={1, 0, 1}&] (* Harvey P. Dale, Aug 26 2016 *)
PROG
(PARI) a(n)=n+4*2^floor(log(n)/log(2))
(Haskell)
import Data.List (transpose)
a004757 n = a004757_list !! (n-1)
a004757_list = 5 : concat (transpose [zs, map (+ 1) zs])
where zs = map (* 2) a004757_list
-- Reinhard Zumkeller, Dec 04 2015
(Python)
def A004757(n): return n+(2<<n.bit_length()) # Chai Wah Wu, Jul 13 2022
CROSSREFS
Cf. A004754 (10), A004755 (11), A004756 (100), A004758 (110), A004759 (111).
KEYWORD
nonn,base,easy
EXTENSIONS
Edited by Ralf Stephan, Oct 12 2003
STATUS
approved
Binary expansion starts 110.
+10
10
6, 12, 13, 24, 25, 26, 27, 48, 49, 50, 51, 52, 53, 54, 55, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213
OFFSET
1,1
LINKS
FORMULA
a(2n) = 2a(n), a(2n+1) = 2a(n) + 1 + 5*[n==0].
a(n) = n + 5 * 2^floor(log_2(n)) = A004757(n) + A053644(n).
a(2^m+k) = 6*2^m + k, m >= 0, 0 <= k < 2^m. - Yosu Yurramendi, Aug 08 2016
EXAMPLE
26 in binary is 11010, so 26 is in sequence.
MATHEMATICA
w = {1, 1, 0}; Select[Range[5, 213], If[# < 2^(Length@ w - 1), True, Take[IntegerDigits[#, 2], Length@ w] == w] &] (* or *)
Table[n + 5*2^Floor@ Log2@ n, {n, 53}] (* Michael De Vlieger, Aug 10 2016 *)
PROG
(PARI) a(n)=n+5*2^floor(log(n)/log(2))
(Haskell)
import Data.List (transpose)
a004758 n = a004758_list !! (n-1)
a004758_list = 6 : concat (transpose [zs, map (+ 1) zs])
where zs = map (* 2) a004758_list
-- Reinhard Zumkeller, Dec 03 2015
(Python)
def A004758(n): return n+(5<<n.bit_length()-1) # Chai Wah Wu, Jul 13 2022
CROSSREFS
Cf. A004754 (10), A004755 (11), A004756 (100), A004757 (101), A004759 (111).
KEYWORD
nonn,base,easy
EXTENSIONS
Edited by Ralf Stephan, Oct 12 2003
STATUS
approved

Search completed in 0.020 seconds