[go: up one dir, main page]

login
Search: a050600 -id:a050600
     Sort: relevance | references | number | modified | created      Format: long | short | data
Column 3 of A050600: a(n) = add1c(n,3).
+20
3
1, 3, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1, 5, 4, 4, 1, 3, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1, 6, 5, 5, 1, 3, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1, 5, 4, 4, 1, 3, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1, 7, 6, 6, 1, 3, 2, 2, 1, 4, 3, 3, 1, 3, 2, 2, 1, 5, 4, 4, 1
OFFSET
0,2
COMMENTS
Image of A001511 under the map x -> {1,x+2,x+1,x+1}. - Charlie Neder, Feb 25 2019
FORMULA
a(4n) = 1, a(4n+1)-2 = a(4n+2)-1 = a(4n+3)-1 = A001511(n) for all n >= 0. - M. F. Hasler, Feb 25 2019
PROG
(PARI) A050604(n)=if((n=divrem(n, 4))[2], valuation(n[1]+1, 2)+2+(n[2]<2), 1) \\ M. F. Hasler, Feb 25 2019
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Jun 22 1999
STATUS
approved
The ruler function: exponent of the highest power of 2 dividing 2n. Equivalently, the 2-adic valuation of 2n.
(Formerly M0127 N0051)
+10
464
1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 6, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 7, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 6, 1, 2, 1, 3, 1, 2, 1, 4, 1
OFFSET
1,2
COMMENTS
Number of 2's dividing 2*n.
a(n) is equivalently the exponent of the smallest power of 2 which does not divide n. - David James Sycamore, Oct 02 2023
a(n) - 1 is the number of trailing zeros in the binary expansion of n.
If you are counting in binary and the least significant bit is numbered 1, the next bit is 2, etc., a(n) is the bit that is incremented when increasing from n-1 to n. - Jud McCranie, Apr 26 2004
Number of steps to reach an integer starting with (n+1)/2 and using the map x -> x*ceiling(x) (cf. A073524).
a(n) is the number of the disk to be moved at the n-th step of the optimal solution to Towers of Hanoi problem (comment from Andreas M. Hinz).
Shows which bit to flip when creating the binary reflected Gray code (bits are numbered from the right, offset is 1). This is essentially equivalent to Hinz's comment. - Adam Kertesz, Jul 28 2001
a(n) is the Hamming distance between n and n-1 (in binary). This is equivalent to Kertesz's comments above. - Tak-Shing Chan (chan12(AT)alumni.usc.edu), Feb 25 2003
Let S(0) = {1}, S(n) = {S(n-1), S(n-1)-{x}, x+1} where x = last term of S(n-1); sequence gives S(infinity). - Benoit Cloitre, Jun 14 2003
The sum of all terms up to and including the first occurrence of m is 2^m-1. - Donald Sampson (marsquo(AT)hotmail.com), Dec 01 2003
m appears every 2^m terms starting with the 2^(m-1)th term. - Donald Sampson (marsquo(AT)hotmail.com), Dec 08 2003
Sequence read mod 4 gives A092412. - Philippe Deléham, Mar 28 2004
If q = 2n/2^A001511(n) and if b(m) is defined by b(0)=q-1 and b(m)=2*b(m-1)+1, then 2n = b(A001511(n)) + 1. - Gerald McGarvey, Dec 18 2004
Repeating pattern ABACABADABACABAE ... - Jeremy Gardiner, Jan 16 2005
Relation to C(n) = Collatz function iteration using only odd steps: a(n) is the number of right bits set in binary representation of A004767(n) (numbers of the form 4*m+3). So for m=A004767(n) it follows that there are exactly a(n) recursive steps where m<C(m). - Lambert Klasen (lambert.klasen(AT)gmx.de), Jan 23 2005
Between every two instances of any positive integer m there are exactly m distinct values (1 through m-1 and one value greater than m). - Franklin T. Adams-Watters, Sep 18 2006
Number of divisors of n of the form 2^k. - Giovanni Teofilatto, Jul 25 2007
Every prefix up to (but not including) the first occurrence of some k >= 2 is a palindrome. - Gary W. Adamson, Sep 24 2008
2*n = 2^A001511 * A000265. - Eric Desbiaux, May 14 2009 [corrected by Alejandro Erickson, Apr 17 2012]
Multiplicative with a(2^k) = k + 1, a(p^k) = 1 for any odd prime p. - Franklin T. Adams-Watters, Jun 09 2009
1 interleaved with (2 interleaved with (3 interleaved with ( ... ))). - Eric D. Burgess (ericdb(AT)gmail.com), Oct 17 2009
A054525 (Möbius transform) * A001511 = A036987 = A047999^(-1) * A001511. - Gary W. Adamson, Oct 26 2009
Equals A051731 * A036987, (inverse Möbius transform of the Fredholm-Rueppel sequence) = A047999 * A036987. - Gary W. Adamson, Oct 26 2009
Cf. A173238, showing links between generalized ruler functions and A000041. - Gary W. Adamson, Feb 14 2010
Given A000041, P(x) = A(x)/A(x^2) with P(x) = (1 + x + 2x^2 + 3x^3 + 5x^4 + 7x^5 + ...), A(x) = (1 + x + 3x^2 + 4x^3 + 10x^4 + 13x^5 + ...), A(x^2) = (1 + x^2 + 3x^4 + 4x^6 + 10x^8 + ...), where A092119 = (1, 1, 3, 4, 10, ...) = Euler transform of the ruler sequence, A001511. - Gary W. Adamson, Feb 11 2010
Subtracting 1 from every term and deleting any 0's yields the same sequence, A001511. - Ben Branman, Dec 28 2011
In the listing of the compositions of n as lists in lexicographic order, a(k) is the last part of composition(k) for all k <= 2^(n-1) and all n, see example. - Joerg Arndt, Nov 12 2012
According to Hinz, et al. (see links), this sequence was studied by Louis Gros in his 1872 pamphlet "Théorie du Baguenodier" and has therefore been called the Gros sequence.
First n terms comprise least squarefree word of length n using positive integers, where "squarefree" means that the word contains no consecutive identical subwords; e.g., 1 contains no square; 11 contains a square but 12 does not; 121 contains no square; both 1211 and 1212 have squares but 1213 does not; etc. - Clark Kimberling, Sep 05 2013
Length of 0-run starting from 2 (10, 100, 110, 1000, 1010, ...), or length of 1-run starting from 1 (1, 11, 101, 111, 1001, 1011, ...) of every second number, from right to left in binary representation. - Armands Strazds, Apr 13 2017
a(n) is also the frequency of the largest 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
As A000005(n) equals the number of even divisors of 2n and A001227(n) = A001227(2n), the formula A001511(n) = A000005(n)/A001227(n) might be read as "The number of even divisors of 2n is always divisible by the number of odd divisors of 2n" (where number of divisors means sum of zeroth powers of divisors). Conjecture: For any nonnegative integer k, the sum of the k-th powers of even divisors of n is always divisible by the sum of the k-th powers of odd divisors of n. - Ivan N. Ianakiev, Jul 06 2019
From Benoit Cloitre, Jul 14 2022: (Start)
To construct the sequence, start from 1's separated by a place 1,,1,,1,,1,,1,,1,,1,,1,,1,,1,,1,,1,,1,,1,...
Then put the 2's in every other remaining place
1,2,1,,1,2,1,,1,2,1,,1,2,1,,1,2,1,,1,2,1,,1,2,1,...
Then the 3's in every other remaining place
1,2,1,3,1,2,1,,1,2,1,3,1,2,1,,1,2,1,3,1,2,1,,1,2,1,...
Then the 4's in every other remaining place
1,2,1,3,1,2,1,4,1,2,1,3,1,2,1,,1,2,1,3,1,2,1,4,1,2,1,...
By iterating this process, we get the ruler function 1,2,1,3,1,2,1,4,1,2,1,3,1,2,1,5,1,2,1,3,1,2,1,4,1,2,1,... (End)
a(n) is the least positive integer k for which there does not exist i+j=n and a(i)=a(j)=k (cf. A322523). - Rémy Sigrist and Jianing Song, Aug 23 2022
a(n) is the smallest positive integer that does not occur in the coincidences of the sequence so far a(1..n-1) and its reverse. - Neal Gersh Tolunsky, Jan 18 2023
REFERENCES
J.-P. Allouche and J. Shallit, Automatic Sequences, Cambridge Univ. Press, 2003.
E. R. Berlekamp, J. H. Conway and R. K. Guy, Winning Ways, Academic Press, NY, 2 vols., 2nd ed., 2001-2003; see Dim- and Dim+ on p. 98; Dividing Rulers, on pp. 436-437; The Ruler Game, pp. 469-470; Ruler Fours, Fives, ... Fifteens on p. 470.
L. Gros, Théorie du Baguenodier, Aimé Vingtrinier, Lyon, 1872.
R. K. Guy, Unsolved Problems in Number Theory, Springer, 1st edition, 1981. See section E22.
A. M. Hinz, The Tower of Hanoi, in Algebras and combinatorics (Hong Kong, 1997), 277-289, Springer, Singapore, 1999.
D. E. Knuth, The Art of Computer Programming, vol. 4A, Combinatorial Algorithms, Section 7.1.3, Problem 41, p. 589.
Andrew Schloss, "Towers of Hanoi" composition, in The Digital Domain. Elektra/Asylum Records 9 60303-2, 1983. Works by Jaffe (Finale to "Silicon Valley Breakdown"), McNabb ("Love in the Asylum"), Schloss ("Towers of Hanoi"), Mattox ("Shaman"), Rush, Moorer ("Lions are Growing") and others.
N. J. A. Sloane, A Handbook of Integer Sequences, Academic Press, 1973 (includes this sequence).
N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
LINKS
J.-P. Allouche and J. Shallit, The ring of k-regular sequences, Theoretical Computer Sci., 98 (1992), 163-197.
J.-P. Allouche and J. Shallit, The ring of k-regular sequences, Theoretical Computer Sci., 98 (1992), 163-197.
Joerg Arndt, Matters Computational (The Fxtbook), p. 9, pp. 733-734
Joerg Arndt, Subset-lex: did we miss an order?, arXiv:1405.6503 [math.CO], 2014.
B. Baker Swart, R. Florez, D. Narayan, and G. Rudolph Extrema Property of the k-Ranking of Directed Paths and Cycles, AKCE International Journal of Graphs and Combinatorics, 13 (2016) 38-53.
Yann Bugeaud and Guo-Niu Han, A combinatorial proof of the non-vanishing of Hankel determinants of the Thue-Morse sequence, Electronic Journal of Combinatorics 21(3) (2014), #P3.26. See G(z) in (1.1).
Antonin Callard, Léo Paviet Salomon, and Pascal Vanier, Computability of extender sets in multidimensional subshifts, arXiv:2401.07549 [cs.DM], 2024.
Imanuel Chen and Michael Z. Spivey, Integral Generalized Binomial Coefficients of Multiplicative Functions, Preprint 2015; Summer Research Paper 238, Univ. Puget Sound.
Vassili Daiev, Greatest divisors of even integers: Problem 636, Math. Mag., 40 (1967), 164-165.
P. Flajolet, J.-C. Raoult, and J. Vuillemin, The number of registers required for evaluating arithmetic expressions, Theoret. Comput. Sci. 9 (1979), no. 1, 99-125.
R. Florez and D. Narayan Maximizing the number of edges in optimal k-rankings, AKCE International Journal of Graphs and Combinatorics, 12.1 (2015) 1-8.
Rigoberto Flórez, Robinson A. Higuita, and Antara Mukherjee, The Star of David and Other Patterns in Hosoya Polynomial Triangles, J. Int. Seq., Vol. 21 (2018), Article 18.4.6, also arXiv:1706.04247 [math.CO], 2017.
Fernando Q. Gouvêa, p-Adic Numbers, Springer-Verlag, 1993; see p. 23.
A. M. Hinz, S. Klavžar, U. Milutinović, and C. Petr, The Tower of Hanoi - Myths and Maths, Birkhäuser 2013. See 'The Gros Sequence', page 60. Book's website
Norbert Hungerbühler and Ernst Specker, A generalization of the Smarandache Function to several variables, INTEGERS 6 (2006) #A23. [See final section.]
Douglas E. Iannucci and Urban Larsson, Game values of arithmetic functions, arXiv:2101.07608 [math.NT], 2021. Section 1.1.2. p. 5.
Jonas Kaiser, On the relationship between the Collatz conjecture and Mersenne prime numbers, arXiv preprint arXiv:1608.00862 [math.GM], 2016.
J. C. Lagarias and N. J. A. Sloane, Approximate squaring (pdf, ps), Experimental Math., 13 (2004), 113-128.
S. Legendre and P. Paclet, On the Permutations Generated by Cyclic Shift , J. Int. Seq. 14 (2011) # 11.3.2.
Subhayan Roy Moulik and Sergii Strelchuk, DQC1-hardness of estimating correlation functions, arXiv:2411.05208 [quant-ph], 2024. See p. 8.
Juan Carlos Nuño and Francisco J. Muñoz, On the ubiquity of the ruler sequence, arXiv:2009.14629 [math.HO], 2020.
Michael Naylor, Abacaba-Dabacaba [updated by Jeremy Gardiner, Sep 11 2015]
Juan Carlos Nuño and Francisco J. Muñoz, The Ruler Sequence Revisited: A Dynamic Perspective, Mathematics (2024) Vol. 12, No. 5, 742.
Simon Plouffe, On the values of the functions ... [zeta and Gamma] ..., arXiv preprint arXiv:1310.7195 [math.NT], 2013.
Joseph Rosenbaum, Elementary Problem E319, American Mathematical Monthly, volume 45, number 10, December 1938, pages 694-696. (The A indices in P at equations 1 and 2.)
Ralf Stephan, Divide-and-conquer generating functions. I. Elementary sequences, arXiv:math/0307027 [math.CO], 2003.
Dinesh Thakur, Gauss sums for function fields, J. Number Theory, Volume 37, Issue 2, February 1991, Pages 242-252.
Dinesh S. Thakur, Continued fraction for the exponential for F_q[T], Journal of Number Theory, 41.2 (1992): 150-155. See page 153.
Dinesh S. Thakur, Patterns of Continued Fractions for the Analogues of e and Related Numbers in the Function Field Case, Journal of Number Theory, 66.1 (1997): 129-147. See p. 130.
Eric Weisstein's World of Mathematics, Binary Carry Sequence, Ruler Function, and Towers of Hanoi
FORMULA
a(n) = A007814(n) + 1.
a(2*n+1) = 1; a(2*n) = 1 + a(n). - Philippe Deléham, Dec 08 2003
a(n) = 2 - A000120(n) + A000120(n-1), n >= 1. - Daniele Parisse
a(n) = 1 + log_2(abs(A003188(n) - A003188(n-1))).
Multiplicative with a(p^e) = e+1 if p = 2; 1 if p > 2. - David W. Wilson, Aug 01 2001
For any real x > 1/2: lim_{N->infinity} (1/N)*Sum_{n=1..N} x^(-a(n)) = 1/(2*x-1); also lim_{N->infinity} (1/N)*Sum_{n=1..N} 1/a(n) = log(2). - Benoit Cloitre, Nov 16 2001
s(n) = Sum_{k=1..n} a(k) is asymptotic to 2*n since s(n) = 2*n - A000120(n). - Benoit Cloitre, Aug 31 2002
For any n >= 0, for any m >= 1, a(2^m*n + 2^(m-1)) = m. - Benoit Cloitre, Nov 24 2002
a(n) = Sum_{d divides n and d is odd} mu(d)*tau(n/d). - Vladeta Jovovic, Dec 04 2002
G.f.: A(x) = Sum_{k>=0} x^(2^k)/(1-x^(2^k)). - Ralf Stephan, Dec 24 2002
a(1) = 1; for n > 1, a(n) = a(n-1) + (-1)^n*a(floor(n/2)). - Vladeta Jovovic, Apr 25 2003
A fixed point of the mapping 1->12; 2->13; 3->14; 4->15; 5->16; ... . - Philippe Deléham, Dec 13 2003
Product_{k>0} (1+x^k)^a(k) is g.f. for A000041(). - Vladeta Jovovic, Mar 26 2004
G.f. A(x) satisfies A(x) = A(x^2) + x/(1-x). - Franklin T. Adams-Watters, Feb 09 2006
a(A118413(n,k)) = A002260(n,k); = a(A118416(n,k)) = A002024(n,k); a(A014480(n)) = A003602(A014480(n)). - Reinhard Zumkeller, Apr 27 2006
Ordinal transform of A003602. - Franklin T. Adams-Watters, Aug 28 2006 (The ordinal transform of a sequence b_0, b_1, b_2, ... is the sequence a_0, a_1, a_2, ... where a_n is the number of times b_n has occurred in {b_0 ... b_n}.)
Could be extended to n <= 0 using a(-n) = a(n), a(0) = 0, a(2*n) = a(n)+1 unless n=0. - Michael Somos, Sep 30 2006
A094267(2*n) = A050603(2*n) = A050603(2*n + 1) = a(n). - Michael Somos, Sep 30 2006
Sequence = A129360 * A000005 = M*V, where M = an infinite lower triangular matrix and V = d(n) as a vector: [1, 2, 2, 3, 2, 4, ...]. - Gary W. Adamson, Apr 15 2007
Row sums of triangle A130093. - Gary W. Adamson, May 13 2007
Dirichlet g.f.: zeta(s)*2^s/(2^s-1). - Ralf Stephan, Jun 17 2007
a(n) = -Sum_{d divides n} mu(2*d)*tau(n/d). - Benoit Cloitre, Jun 21 2007
G.f.: x/(1-x) = Sum_{n>=1} a(n)*x^n*( 1 - x^n ). - Paul D. Hanna, Jun 22 2007
With S(n): 2^n - 1 first elements of the sequence then S(0) = {} (empty list) and if n > 0, S(n) = S(n-1), n, S(n-1). - Yann David (yann_david(AT)hotmail.com), Mar 21 2010
a(n) = log_2(A046161(n)/A046161(n-1)). - Johannes W. Meijer, Nov 04 2012
a((2*n-1)*2^p) = p+1, p >= 0 and n >= 1. - Johannes W. Meijer, Feb 05 2013
a(n+1) = 1 + Sum_{j=0..ceiling(log_2(n+1))} (j * (1 - abs(sign((n mod 2^(j + 1)) - 2^j + 1)))). - Enrico Borba, Oct 01 2015
Conjecture: a(n) = A181988(n)/A003602(n). - L. Edson Jeffery, Nov 21 2015
a(n) = log_2(A006519(n)) + 1. - Doug Bell, Jun 02 2017
Inverse Moebius transform of A209229. - Andrew Howroyd, Aug 04 2018
a(n) = 1 + (A183063(n)/A001227(n)). - Omar E. Pol, Nov 06 2018 (after Franklin T. Adams-Watters)
a(n) = log_2((Xor(2*n,2*n-1)+1)/2). - Gary Detlefs, Dec 13 2018
(2^(a(n)-1)-1)*(n mod 4) = 2*floor(((n+1) mod 4)/3). - Gary Detlefs, Dec 14 2018
a(n) = A000005(n)/A001227(n). - Ivan N. Ianakiev, Jul 05 2019
a(n) = Sum_{j=1..r} (j/2^j)*(Product_{k=1..j} (1 - (-1)^floor( (n+2^(j-1))/2^(k-1) ))), for n < a predefined 2^r. - Adriano Caroli, Sep 30 2019
EXAMPLE
For example, 2^1|2, 2^2|4, 2^1|6, 2^3|8, 2^1|10, 2^2|12, ... giving the initial terms 1, 2, 1, 3, 1, 2, ...
From Omar E. Pol, Jun 12 2009: (Start)
Triangle begins:
1;
2,1;
3,1,2,1;
4,1,2,1,3,1,2,1;
5,1,2,1,3,1,2,1,4,1,2,1,3,1,2,1;
6,1,2,1,3,1,2,1,4,1,2,1,3,1,2,1,5,1,2,1,3,1,2,1,4,1,2,1,3,1,2,1;
7,1,2,1,3,1,2,1,4,1,2,1,3,1,2,1,5,1,2,1,3,1,2,1,4,1,2,1,3,1,2,1,6,1,2,1,3,...
(End)
S(0) = {} S(1) = 1 S(2) = 1, 2, 1 S(3) = 1, 2, 1, 3, 1, 2, 1 S(4) = 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1. - Yann David (yann_david(AT)hotmail.com), Mar 21 2010
From Joerg Arndt, Nov 12 2012: (Start)
The 16 compositions of 5 as lists in lexicographic order:
[ n] a(n) composition
[ 1] [ 1] [ 1 1 1 1 1 ]
[ 2] [ 2] [ 1 1 1 2 ]
[ 3] [ 1] [ 1 1 2 1 ]
[ 4] [ 3] [ 1 1 3 ]
[ 5] [ 1] [ 1 2 1 1 ]
[ 6] [ 2] [ 1 2 2 ]
[ 7] [ 1] [ 1 3 1 ]
[ 8] [ 4] [ 1 4 ]
[ 9] [ 1] [ 2 1 1 1 ]
[10] [ 2] [ 2 1 2 ]
[11] [ 1] [ 2 2 1 ]
[12] [ 3] [ 2 3 ]
[13] [ 1] [ 3 1 1 ]
[14] [ 2] [ 3 2 ]
[15] [ 1] [ 4 1 ]
[16] [ 5] [ 5 ]
a(n) is the last part in each list.
(End)
From Omar E. Pol, Aug 20 2013: (Start)
Also written as a triangle in which the right border gives A000027 and row lengths give A011782 and row sums give A000079 the sequence begins:
1;
2;
1,3;
1,2,1,4;
1,2,1,3,1,2,1,5;
1,2,1,3,1,2,1,4,1,2,1,3,1,2,1,6;
1,2,1,3,1,2,1,4,1,2,1,3,1,2,1,5,1,2,1,3,1,2,1,4,1,2,1,3,1,2,1,7;
(End)
G.f. = x + 2*x^2 + x^3 + 3*x^4 + x^5 + 2*x^6 + x^7 + 4*x^8 + x^9 + 2*x^10 + ...
MAPLE
A001511 := n->2-wt(n)+wt(n-1); # where wt is defined in A000120
# This is the binary logarithm of the denominator of (256^n-1)B_{8n}/n, in Maple parlance a := n -> log[2](denom((256^n-1)*bernoulli(8*n)/n)). - Peter Luschny, May 31 2009
A001511 := n -> padic[ordp](2*n, 2): seq(A001511(n), n=1..105); # Peter Luschny, Nov 26 2010
a:= n-> ilog2((Bits[Xor](2*n, 2*n-1)+1)/2): seq(a(n), n=1..50); # Gary Detlefs, Dec 13 2018
MATHEMATICA
Array[ If[ Mod[ #, 2] == 0, FactorInteger[ # ][[1, 2]], 0] &, 105] + 1 (* or *)
Nest[ Flatten[ # /. a_Integer -> {1, a + 1}] &, {1}, 7] (* Robert G. Wilson v, Mar 04 2005 *)
IntegerExponent[2*n, 2] (* Alexander R. Povolotsky, Aug 19, 2011 *)
myHammingDistance[n_, m_] := Module[{g = Max[m, n], h = Min[m, n]}, b1 = IntegerDigits[g, 2]; b2 = IntegerDigits[h, 2, Length[b1]]; HammingDistance[b1, b2]] (* Vladimir Shevelev A206853 *) Table[ myHammingDistance[n, n - 1], {n, 111}] (* Robert G. Wilson v, Apr 05 2012 *)
Table[Position[Reverse[IntegerDigits[n, 2]], 1, 1, 1], {n, 110}]//Flatten (* Harvey P. Dale, Aug 18 2017 *)
PROG
(PARI) a(n) = sum(k=0, floor(log(n)/log(2)), floor(n/2^k)-floor((n-1)/2^k)) /* Ralf Stephan */
(PARI) a(n)=if(n%2, 1, factor(n)[1, 2]+1) /* Jon Perry, Jun 06 2004 */
(PARI) {a(n) = if( n, valuation(n, 2) + 1, 0)}; /* Michael Somos, Sep 30 2006 */
(PARI) {a(n)=if(n==1, 1, polcoeff(x-sum(k=1, n-1, a(k)*x^k*(1-x^k)*(1-x+x*O(x^n))), n))} /* Paul D. Hanna, Jun 22 2007 */
(Haskell)
a001511 n = length $ takeWhile ((== 0) . (mod n)) a000079_list
-- Reinhard Zumkeller, Sep 27 2011
(Haskell) a001511 n | odd n = 1 | otherwise = 1 + a001511 (n `div` 2)
-- Walt Rorie-Baety, Mar 22 2013
(Sage) [valuation(2*n, 2) for n in (1..105)] # Bruno Berselli, Nov 23 2015
(Magma) [Valuation(2*n, 2): n in [1..105]]; // Bruno Berselli, Nov 23 2015
(MATLAB) nmax=5; r=1; for n=2:nmax; r=[r n r]; end % Adriano Caroli, Feb 26 2016
(Python)
def a(n): return bin(n)[2:][::-1].index("1") + 1 # Indranil Ghosh, May 11 2017
(Python) A001511 = lambda n: (n&-n).bit_length() # M. F. Hasler, Apr 09 2020
(Python)
def A001511(n): return (~n & n-1).bit_length()+1 # Chai Wah Wu, Jul 01 2022
(Scheme) (define (A001511 n) (let loop ((n n) (e 1)) (if (odd? n) e (loop (/ n 2) (+ 1 e))))) ;; Antti Karttunen, Oct 06 2017
CROSSREFS
Column 1 of table A050600.
Sequence read mod 2 gives A035263.
Sequence is bisection of A007814, A050603, A050604, A067029, A089309.
This is Guy Steele's sequence GS(4, 2) (see A135416).
Cf. A005187 (partial sums), A085058 (bisection), A171977 (2^a(n)).
Cf. A287896, A002487, A209229 (Mobius trans.), A092673 (Dirichlet inv.).
Cf. generalized ruler functions for k=3,4,5: A051064, A115362, A055457.
KEYWORD
mult,nonn,nice,easy,core,hear,changed
EXTENSIONS
Name edited following suggestion by David James Sycamore, Oct 05 2023
STATUS
approved
n appears n+1 times. Also the array A(n,k) = n+k (n >= 0, k >= 0) read by antidiagonals. Also inverse of triangular numbers.
+10
362
0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12
OFFSET
0,4
COMMENTS
Also triangle read by rows: T(n,k), n>=0, k>=0, in which n appears n+1 times in row n. - Omar E. Pol, Jul 15 2012
The PARI functions t1, t2 can be used to read a triangular array T(n,k) (n >= 0, 0 <= k <= n-1) by rows from left to right: n -> T(t1(n), t2(n)). - Michael Somos, Aug 23 2002
Number of terms in partition of n with greatest number of distinct terms. - Amarnath Murthy, May 20 2001
Summation table for (x+y) = (0+0),(0+1),(1+0),(0+2),(1+1),(2+0), ...
Also the number of triangular numbers less than or equal to n, not counting 0 as triangular. - Robert G. Wilson v, Oct 21 2005
Permutation of A116939: a(n) = A116939(A116941(n)), a(A116942(n)) = A116939(n). - Reinhard Zumkeller, Feb 27 2006
Maximal size of partitions of n into distinct parts, see A000009. - Reinhard Zumkeller, Jun 13 2009
Also number of digits of A000462(n). - Reinhard Zumkeller, Mar 27 2011
Also the maximum number of 1's contained in the list of hook-lengths of a partition of n. E.g., a(4)=2 because hooks of partitions of n=4 comprise {4,3,2,1}, {4,2,1,1}, {3,2,2,1}, {4,1,2,1}, {4,3,2,1} where the number of 1's in each is 1,2,1,2,1. Hence the maximum is 2. - T. Amdeberhan, Jun 03 2012
Fan, Yang, and Yu (2012) prove a conjecture of Amdeberhan on the generating function of a(n). - Jonathan Sondow, Dec 17 2012
Also the number of partitions of n into distinct parts p such that max(p) - min(p) <= length(p). - Clark Kimberling, Apr 18 2014
Also the maximum number of occurrences of any single value among the previous terms. - Ivan Neretin, Sep 20 2015
Where records occur gives A000217. - Omar E. Pol, Nov 05 2015
Also number of peaks in the largest Dyck path of the symmetric representation of sigma(n), n >= 1. Cf. A237593. - Omar E. Pol, Dec 19 2016
LINKS
Anna R. B. Fan, Harold R. L. Yang, and Rebecca T. Yu, On the Maximum Number of k-Hooks of Partitions of n, arXiv:1212.3505 [math.CO], 2012.
FORMULA
a(n) = floor((sqrt(1+8*n)-1)/2). - Antti Karttunen
a(n) = floor(-1/2 + sqrt(2*n+b)) with 1/4 <= b < 9/4 or a(n) = floor((sqrt(8*n+b)-1)/2) with 1 <= b < 9. - Michael A. Childers (childers_moof(AT)yahoo.com), Nov 11 2001
a(n) = f(n,0) with f(n,k) = k if n <= k, otherwise f(n-k-1, k+1). - Reinhard Zumkeller, May 23 2009
a(n) = 2*n + 1 - A001614(n+1) = n + 1 - A122797(n+1). - Reinhard Zumkeller, Feb 12 2012
a(n) = k if k*(k+1)/2 <= n < (k+1)*(k+2)/2. - Jonathan Sondow, Dec 17 2012
G.f.: (1-x)^(-1)*Sum_{n>=1} x^(n*(n+1)/2) = (Theta_2(0,x^(1/2)) - 2*x^(1/8))/(2*x^(1/8)*(1-x)) where Theta_2 is a Jacobi Theta function. - Robert Israel, May 21 2015
a(n) = floor((A000196(1+8*n)-1)/2). - Pontus von Brömssen, Dec 10 2018
a(n+1) = a(n-a(n)) + 1, a(0) = 0. - Rok Cestnik, Dec 29 2020
a(n) = A001227(n) + A238005(n), n >= 1. - Omar E. Pol, Sep 30 2021
Sum_{n>=1} (-1)^(n+1)/a(n) = log(2)/2 (cf. A016655). - Amiram Eldar, Sep 24 2023
G.f. as array: (x + y - 2*x*y)/((1 - x)^2*(1 - y)^2). - Stefano Spezia, Dec 20 2023 [corrected by Stefano Spezia, Apr 22 2024]
EXAMPLE
G.f. = x + x^2 + 2*x^3 + 2*x^4 + 2*x^5 + 3*x^6 + 3*x^7 + 3*x^8 + 3*x^9 + 4*x^10 + ...
As triangle, the sequence starts
0;
1, 1;
2, 2, 2;
3, 3, 3, 3;
4, 4, 4, 4, 4;
5, 5, 5, 5, 5, 5;
6, 6, 6, 6, 6, 6, 6;
7, 7, 7, 7, 7, 7, 7, 7;
8, 8, 8, 8, 8, 8, 8, 8, 8;
...
MAPLE
A003056 := (n, k) -> n: # Peter Luschny, Oct 29 2011
a := [ 0 ]: for i from 1 to 15 do for j from 1 to i+1 do a := [ op(a), i ]; od: od: a;
A003056 := proc(n)
floor((sqrt(1+8*n)-1)/2) ;
end proc: # R. J. Mathar, Jul 10 2015
MATHEMATICA
f[n_] := Floor[(Sqrt[1 + 8n] - 1)/2]; Table[ f[n], {n, 0, 87}] (* Robert G. Wilson v, Oct 21 2005 *)
Table[x, {x, 0, 13}, {y, 0, x}] // Flatten
T[ n_, k_] := If[ n >= k >= 0, n, 0]; (* Michael Somos, Dec 22 2016 *)
Flatten[Table[PadRight[{}, n+1, n], {n, 0, 12}]] (* Harvey P. Dale, Jul 03 2021 *)
PROG
(PARI) A003056(n)=(sqrtint(8*n+1)-1)\2 \\ M. F. Hasler, Oct 08 2011
(PARI) t1(n)=floor(-1/2+sqrt(2+2*n)) /* A003056 */
(PARI) t2(n)=n-binomial(floor(1/2+sqrt(2+2*n)), 2) /* A002262 */
(Haskell)
a003056 = floor . (/ 2) . (subtract 1) .
sqrt . (+ 1) . (* 8) . fromIntegral
a003056_row n = replicate (n + 1) n
a003056_tabl = map a003056_row [0..]
a003056_list = concat $ a003056_tabl
-- Reinhard Zumkeller, Aug 02 2014, Oct 17 2010
(Magma) [Floor((Sqrt(1+8*n)-1)/2): n in [0..80]]; // Vincenzo Librandi, Oct 23 2011
(Python)
from math import isqrt
def A003056(n): return (k:=isqrt(m:=n+1<<1))+int((m<<2)>(k<<2)*(k+1)+1)-1 # Chai Wah Wu, Jul 26 2022
CROSSREFS
a(n) = A002024(n+1)-1.
Cf. A000196, A000217, A000462, A001227, A001462, A001614, A004247 (multiplication table), A006463 (partial sums), A016655, A050600, A050602, A048645, A122797, A131507, A238005.
Partial sums of A073424.
KEYWORD
nonn,easy,nice,tabl
EXTENSIONS
Definition clarified by N. J. A. Sloane, Dec 08 2020
STATUS
approved
a(n) = (n AND floor(n/2)), where AND is bitwise and-operator (A004198).
+10
14
0, 0, 0, 1, 0, 0, 2, 3, 0, 0, 0, 1, 4, 4, 6, 7, 0, 0, 0, 1, 0, 0, 2, 3, 8, 8, 8, 9, 12, 12, 14, 15, 0, 0, 0, 1, 0, 0, 2, 3, 0, 0, 0, 1, 4, 4, 6, 7, 16, 16, 16, 17, 16, 16, 18, 19, 24, 24, 24, 25, 28, 28, 30, 31, 0, 0, 0, 1, 0, 0, 2, 3, 0, 0, 0, 1, 4, 4, 6, 7, 0
OFFSET
0,7
COMMENTS
To prove that (n AND floor(n/2)) = (3n-(n XOR 2n))/4 (= A048728(n)/4), we first multiply both sides by 4, to get 2*(n AND 2n) = (3n - (n XOR 2n)) and then rearrange terms: 3n = (n XOR 2n) + 2*(n AND 2n), which fits perfectly to the identity A+B = (A XOR B) + 2*(A AND B) (given by Schroeppel in HAKMEM link).
The number of 1's through 4*2^n appears to yield A000045(n+1). - Ben Burns, Jun 12 2017
LINKS
Beeler, M., Gosper, R. W. and Schroeppel, R., HAKMEM, ITEM 23 (Schroeppel)
FORMULA
a(n) = A048728(n)/4. (This was the original definition. AND-formula found Jan 01 2007).
MAPLE
seq(Bits:-And(n, floor(n/2)), n=0..200); # Robert Israel, Feb 29 2016
MATHEMATICA
Table[BitAnd[n, Floor[n/2]], {n, 0, 127}] (* T. D. Noe, Aug 13 2012 *)
PROG
(PARI) a(n) = bitand(n, n\2); \\ Michel Marcus, Feb 29 2016
(Python)
def a(n): return n&int(n/2) # Indranil Ghosh, Jun 13 2017
CROSSREFS
Cf. A003714 (positions of zeros), A003188, A050600.
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, Apr 26 1999
EXTENSIONS
New formula and more terms added by Antti Karttunen, Jan 01 2007
STATUS
approved
Square array A(x,y), read by antidiagonals, where A(x,y) = 0 if (x AND y) = 0, otherwise A(x,y) = 1+A(x XOR y, 2*(x AND y)).
+10
9
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 1, 2, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 3, 1, 3, 2, 3, 0, 0, 0, 2, 2, 1, 1, 2, 2, 0, 0, 0, 1, 0, 2, 1, 1, 1, 2, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 2, 1, 2, 0, 2, 1, 2, 0, 2, 1, 2, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0
OFFSET
0,12
COMMENTS
Array is symmetric and is read by antidiagonals: (0,0), (0,1), (1,0), (0,2), (1,1), (2,0), etc. - Antti Karttunen, Sep 04 2023
Comment from N. J. A. Sloane, Jun 21 2011: Apparently the same as the following sequence. Infinite square array read by antidiagonals, where T(m,n) = length of longest carry propagation when u and v are added in binary, for u >= 0, v >= 0.
See A192054 for definition of carry propagation. For example, T(3,5) = 3, since adding 011 + 101 in binary, the initial 1 propagates three places.
LINKS
Beeler, M., Gosper, R. W. and Schroeppel, R., HAKMEM, ITEM 23 (Schroeppel) [(A AND B) + (A OR B) = A + B = (A XOR B) + 2 (A AND B).]
Nicholas Pippenger, Analysis of carry propagation in addition: an elementary approach, J. Algorithms 42 (2002), 317-333.
FORMULA
If A004198(x,y) = 0, then A(x,y) = 0, otherwise A(x,y) = 1 + A(A003987(x,y), 2*A004198(x,y)), where A004198 and A003987 are bitwise-AND and bitwise-XOR respectively.
EXAMPLE
The top left corner of the square array:
| 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
-----+--------------------------------------------------------
0 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1 | 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4,
2 | 0, 0, 1, 1, 0, 0, 2, 2, 0, 0, 1, 1, 0, 0, 3, 3,
3 | 0, 2, 1, 1, 0, 3, 2, 2, 0, 2, 1, 1, 0, 4, 3, 3,
4 | 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 2, 2, 2, 2,
5 | 0, 1, 0, 3, 1, 1, 1, 2, 0, 1, 0, 4, 2, 2, 2, 2,
6 | 0, 0, 2, 2, 1, 1, 1, 1, 0, 0, 3, 3, 2, 2, 2, 2,
7 | 0, 3, 2, 2, 1, 2, 1, 1, 0, 4, 3, 3, 2, 2, 2, 2,
8 | 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
9 | 0, 1, 0, 2, 0, 1, 0, 4, 1, 1, 1, 2, 1, 1, 1, 3,
10 | 0, 0, 1, 1, 0, 0, 3, 3, 1, 1, 1, 1, 1, 1, 2, 2,
11 | 0, 2, 1, 1, 0, 4, 3, 3, 1, 2, 1, 1, 1, 3, 2, 2,
12 | 0, 0, 0, 0, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1,
13 | 0, 1, 0, 4, 2, 2, 2, 2, 1, 1, 1, 3, 1, 1, 1, 2,
14 | 0, 0, 3, 3, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1,
15 | 0, 4, 3, 3, 2, 2, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1,
etc.
MAPLE
add3c := proc(a, b) option remember; if(0 = ANDnos(a, b)) then RETURN(0); else RETURN(1+add3c(XORnos(a, b), 2*ANDnos(a, b))); fi; end;
MATHEMATICA
a[n_, k_] := a[n, k] = If[0 == BitAnd[n, k], 0, 1 + a[BitXor[n, k], 2*BitAnd[n, k]]]; Table[a[n - k, k], {n, 0, 14}, {k, 0, n}] // Flatten (* Jean-François Alcover, Jan 16 2014, updated Mar 06 2016 after Maple *)
PROG
(PARI)
up_to = 120;
A050602sq(x, y) = if(!bitand(x, y), 0, 1+A050602sq(bitxor(x, y), 2*bitand(x, y)));
A050602list(up_to) = { my(v = vector(up_to), i=0); for(a=0, oo, for(col=0, a, i++; if(i > up_to, return(v)); v[i] = A050602sq(col, a-col))); (v); };
v050602 = A050602list(up_to);
A050602(n) = v050602[1+n]; \\ Antti Karttunen, Sep 04 2023
CROSSREFS
Row/Column 1: A007814, Row/Column 2: A050605, Row/Column 3: A050606. See also A372554 [A(n, 2n+1)].
Cf. also A192054.
Cf. also A072030 (A285721) for similar arrays computed for an elementary Euclidean algorithm.
KEYWORD
nonn,tabl,nice
AUTHOR
Antti Karttunen, Jun 22 1999
EXTENSIONS
Name edited by Antti Karttunen, Sep 04 2023
STATUS
approved
A001511 with every term repeated.
+10
9
1, 1, 2, 2, 1, 1, 3, 3, 1, 1, 2, 2, 1, 1, 4, 4, 1, 1, 2, 2, 1, 1, 3, 3, 1, 1, 2, 2, 1, 1, 5, 5, 1, 1, 2, 2, 1, 1, 3, 3, 1, 1, 2, 2, 1, 1, 4, 4, 1, 1, 2, 2, 1, 1, 3, 3, 1, 1, 2, 2, 1, 1, 6, 6, 1, 1, 2, 2, 1, 1, 3, 3, 1, 1, 2, 2, 1, 1, 4, 4, 1, 1, 2, 2, 1, 1, 3, 3, 1, 1, 2, 2, 1, 1, 5, 5, 1, 1, 2, 2, 1, 1, 3, 3, 1, 1, 2, 2, 1, 1, 4
OFFSET
0,3
COMMENTS
Column 2 of A050600: a(n) = add1c(n,2).
Absolute values of A094267.
Consider the Collatz (or 3x+1) problem and the iterative sequence c(k) where c(0)=n is a positive integer and c(k+1)=c(k)/2 if c(k) is even, c(k+1)=(3*c(k)+1)/2 if c(k) is odd. Then a(n) is the minimum number of iterations in order to have c(a(n)) odd if n is even or c(a(n)) even if n is odd. - Benoit Cloitre, Nov 16 2001
LINKS
Cristian Cobeli, Mihai Prunescu, and Alexandru Zaharescu, A growth model based on the arithmetic Z-game, arXiv:1511.04315 [math.NT], 2015.
Francis Laclé, 2-adic parity explorations of the 3n+ 1 problem, hal-03201180v2 [cs.DM], 2021.
FORMULA
Equals A053398(2, n).
G.f.: (1+x)/x^2 * Sum(k>=1, x^(2^k)/(1-x^(2^k))). - Ralf Stephan, Apr 12 2002
a(n) = A136480(n+1). - Reinhard Zumkeller, Dec 31 2007
a(n) = A007814(n + 2 - n mod 2). - James Spahlinger, Oct 11 2013, corrected by Charles R Greathouse IV, Oct 14 2013
a(2n) = a(2n+1). 1 <= a(n) <= log_2(n+2). - Charles R Greathouse IV, Oct 14 2013
a(n) = A007814(n+1)+A007814(n+2).
a(n) = (-1)^n * A094267(n). - Michael Somos, May 11 2014
a(n) = A007814(floor(n/2)+1). - Chai Wah Wu, Jul 07 2022
Asymptotic mean: lim_{m->oo} (1/m) * Sum_{k=0..m} a(k) = 2. - Amiram Eldar, Sep 15 2022
MATHEMATICA
With[{c=Table[Position[Reverse[IntegerDigits[n, 2]], 1, 1, 1], {n, 110}]// Flatten}, Riffle[c, c]] (* Harvey P. Dale, Dec 06 2018 *)
PROG
(PARI) a(n)=valuation(n+2-n%2, 2) \\ Charles R Greathouse IV, Oct 14 2013
(PARI) {a(n) = my(A); if( n<0, 0, A = sum(k=1, length( binary(n+2)) - 1, x^(2^k) / (1 - x^(2^k)), x^3 * O(x^n)); polcoeff( A * (1 + x) / x^2, n))}; /* Michael Somos, May 11 2014 */
(Python)
def A050603(n): return ((m:=n>>1)&~(m+1)).bit_length()+1 # Chai Wah Wu, Jul 07 2022
CROSSREFS
Bisection gives column 1 of A050600: A001511.
KEYWORD
nonn,easy
AUTHOR
Antti Karttunen Jun 22 1999
EXTENSIONS
Definition simplified by N. J. A. Sloane, Aug 27 2016
STATUS
approved
T(n,k) = length of longest carry sequence when adding k to n in binary representation, 1 <= k <= n (triangular array).
+10
4
1, 0, 1, 2, 1, 1, 0, 0, 0, 1, 1, 0, 3, 1, 1, 0, 2, 2, 1, 1, 1, 3, 2, 2, 1, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 2, 0, 1, 0, 4, 1, 1, 0, 1, 1, 0, 0, 3, 3, 1, 1, 1, 2, 1, 1, 0, 4, 3, 3, 1, 2, 1, 1, 0, 0, 0, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 0, 4, 2, 2, 2, 2, 1, 1, 1, 3, 1, 1, 0, 3, 3, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1, 1
OFFSET
1,4
COMMENTS
T(n,1) = A007814(n+1), T(n,n) = 1; for n>1: T(n,n-1) = A043545(n+1); T(n,k) <= A070940(n) = T(n, A080079(n)).
T(n,k) = A050600(n+k,k) - 1. - Reinhard Zumkeller, Aug 03 2014
EXAMPLE
Triangle begins:
1
0 1
2 1 1
0 0 0 1
1 0 3 1 1
0 2 2 1 1 1
3 2 2 1 2 1 1
PROG
(Haskell)
import Data.Bits (xor, (.&.), shiftL)
a080080 :: Int -> Int -> Int
a080080 n k = addc n k 0 where
addc x y z | y == 0 = z - 1
| otherwise = addc (x `xor` y) (shiftL (x .&. y) 1) (z + 1)
a080080_row n = map (a080080 n) [1..n]
a080080_tabl = map a080080_row [1..]
-- Reinhard Zumkeller, Apr 22 2013
CROSSREFS
Cf. A050600.
KEYWORD
nonn,tabl,nice
AUTHOR
Reinhard Zumkeller, Jan 26 2003
STATUS
approved
Recursion counts for summation table A003056 with formula a(0,x) = x, a(y,0) = y, a(y,x) = a((y XOR x),2*(y AND x))
+10
2
0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 2, 1, 2, 0, 0, 1, 2, 2, 1, 0, 0, 2, 1, 1, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 3, 2, 3, 1, 3, 2, 3, 0, 0, 1, 3, 3, 2, 2, 3, 3, 1, 0, 0, 2, 1, 3, 2, 1, 2, 3, 1, 2, 0, 0, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 0, 0, 3, 2, 3, 1, 3, 1, 3, 1, 3, 2, 3, 0, 0, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 0, 0, 2, 1, 2, 1, 2, 1, 1, 1, 2, 1, 2, 1, 2, 0
OFFSET
0,12
FORMULA
a(n) -> add2c( (n-((trinv(n)*(trinv(n)-1))/2)), (((trinv(n)-1)*(((1/2)*trinv(n))+1))-n) )
MAPLE
add2c := proc(a, b) option remember; if((0 = a) or (0 = b)) then RETURN(0); else RETURN(1+add_c(XORnos(a, b), 2*ANDnos(a, b))); fi; end;
MATHEMATICA
trinv[n_] := Floor[(1/2)*(Sqrt[8*n + 1] + 1)];
Sum2c[a_, b_] := Sum2c[a, b] = If[0 == a || 0 == b, Return[0], Return[ Sum2c[BitXor[a, b], 2*BitAnd[a, b]] + 1]];
a[n_] := Sum2c[n - (1/2)*trinv[n]*(trinv[n] - 1), (trinv[n] - 1)*(trinv[ n]/2 + 1) - n];
Table[a[n], {n, 0, 120}](* Jean-François Alcover, Mar 07 2016, adapted from Maple *)
CROSSREFS
Cf. A050600, A050602, A003056, A048720 (for the Maple implementation of trinv and XORnos, ANDnos)
KEYWORD
nonn,tabl
AUTHOR
Antti Karttunen, Jun 22 1999
STATUS
approved

Search completed in 0.080 seconds