cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A018900 Sums of two distinct powers of 2.

This page as a plain text file.
%I A018900 #155 Apr 04 2025 01:15:21
%S A018900 3,5,6,9,10,12,17,18,20,24,33,34,36,40,48,65,66,68,72,80,96,129,130,
%T A018900 132,136,144,160,192,257,258,260,264,272,288,320,384,513,514,516,520,
%U A018900 528,544,576,640,768,1025,1026,1028,1032,1040,1056,1088,1152,1280,1536,2049,2050,2052,2056,2064,2080,2112,2176,2304,2560,3072
%N A018900 Sums of two distinct powers of 2.
%C A018900 Appears to give all k such that 8 is the highest power of 2 dividing A005148(k). - _Benoit Cloitre_, Jun 22 2002
%C A018900 Seen as a triangle read by rows, T(n,k) = 2^(k-1) + 2^n, 1 <= k <= n, the sum of the n-th row equals A087323(n). - _Reinhard Zumkeller_, Jun 24 2009
%C A018900 Numbers whose base-2 sum of digits is 2. - _Tom Edgar_, Aug 31 2013
%C A018900 All odd terms are A000051. - _Robert G. Wilson v_, Jan 03 2014
%C A018900 A239708 holds the subsequence of terms m such that m - 1 is prime. - _Hieronymus Fischer_, Apr 20 2014
%H A018900 T. D. Noe and Hieronymus Fischer, <a href="/A018900/b018900.txt">Table of n, a(n) for n = 1..10000</a> [terms 1..1000 from T. D. Noe]
%H A018900 Michael Beeler, R. William Gosper, and Richard Schroeppel, <a href="https://dspace.mit.edu/handle/1721.1/6086">HAKMEM</a>, MIT Artificial Intelligence Laboratory report AIM-239, February 1972.  Item 175 page 81 by Gosper for iterating.  Also <a href="http://www.inwap.com/pdp10/hbaker/hakmem/hacks.html#item175">HTML transcription</a>.
%H A018900 Tilman Piesk, <a href="http://commons.wikimedia.org/wiki/File:8_choose_2_array.svg">Square array in reverse binary</a>
%F A018900 a(n) = 2^trinv(n-1) + 2^((n-1)-((trinv(n-1)*(trinv(n-1)-1))/2)), i.e., 2^A002024(n)+2^A002262(n-1). - _Antti Karttunen_
%F A018900 a(n) = A059268(n-1) + A140513(n-1). A000120(a(n)) = 2. Complement of A161989. A151774(a(n)) = 1. - _Reinhard Zumkeller_, Jun 24 2009
%F A018900 A073267(a(n)) = 2. - _Reinhard Zumkeller_, Mar 07 2012
%F A018900 Start with A000051. If n is in sequence, then so is 2n. - _Ralf Stephan_, Aug 16 2013
%F A018900 a(n) = A057168(a(n-1)) for n>1 and a(1) = 3. - _Marc LeBrun_, Jan 01 2014
%F A018900 From _Hieronymus Fischer_, Apr 20 2014: (Start)
%F A018900 Formulas for a general parameter b according to a(n) = b^i + b^j, i>j>=0; b = 2 for this sequence.
%F A018900 a(n) = b^i + b^j, where i = floor((sqrt(8n - 1) + 1)/2), j = n - 1 - i*(i - 1)/2 [for a Smalltalk implementation see Prog section, method distinctPowersOf: b (2 versions)].
%F A018900 a(A000217(n)) = (b + 1)*b^(n-1) = b^n + b^(n-1).
%F A018900 a(A000217(n)+1) = 1 + b^(n+1).
%F A018900 a(n + 1 + floor((sqrt(8n - 1) + 1)/2)) = b*a(n).
%F A018900 a(n + 1 + floor(log_b(a(n)))) = b*a(n).
%F A018900 a(n + 1) = b^2/(b+1) * a(n) + 1, if n is a triangular number (s. A000217).
%F A018900 a(n + 1) = b*a(n) + (1-b)* b^floor((sqrt(8n - 1) + 1)/2), if n is not a triangular number.
%F A018900 The next term can also be calculated without using the index n. Let m be a term and i = floor(log_b(m)), then:
%F A018900 a(n + 1) = b*m + (1-b)* b^i, if floor(log_b(m/(b+1))) + 1 < i,
%F A018900 a(n + 1) = b^2/(b+1) * m + 1, if floor(log_b(m/(b+1))) + 1 = i.
%F A018900 Partial sum:
%F A018900 Sum_{k=1..n} a(k) = ((((b-1)*(j+1)+i-1)*b^(i-j) + b)*b^j - i)/(b-1), where i = floor((sqrt(8*n - 1) + 1)/2), j = n - 1 - i*(i - 1)/2.
%F A018900 Inverse:
%F A018900 For each sequence term m, the index n such that a(n) = m is determined by n := i*(i-1)/2 + j + 1, where i := floor(log_b(m)), j := floor(log_b(m - b^floor(log_b(m)))) [for a Smalltalk implementation see Prog section, method invertedDistinctPowersOf: b].
%F A018900 Inequalities:
%F A018900 a(n) <= (b+1)/b * b^floor(sqrt(2n)+1/2), equality holds for triangular numbers.
%F A018900 a(n) > b^floor(sqrt(2n)+1/2).
%F A018900 a(n) < b^sqrt(2n)*sqrt(b).
%F A018900 a(n) > b^sqrt(2n)/sqrt(b).
%F A018900 Asymptotic behavior:
%F A018900 lim sup a(n)/b^sqrt(2n) = sqrt(b).
%F A018900 lim inf a(n)/b^sqrt(2n) = 1/sqrt(b).
%F A018900 lim sup a(n)/b^(floor(sqrt(2n))) = b.
%F A018900 lim inf a(n)/b^(floor(sqrt(2n))) = 1.
%F A018900 lim sup a(n)/b^(floor(sqrt(2n)+1/2)) = (b+1)/b.
%F A018900 lim inf a(n)/b^(floor(sqrt(2n)+1/2)) = 1.
%F A018900 (End)
%F A018900 Sum_{n>=1} 1/a(n) = A179951. - _Amiram Eldar_, Oct 06 2020
%e A018900 From _Hieronymus Fischer_, Apr 27 2014: (Start)
%e A018900 a(1) = 3, since 3 = 2^1 + 2^0.
%e A018900 a(5) = 10, since 10 = 2^3 + 2^1.
%e A018900 a(10^2) = 16640
%e A018900 a(10^3) = 35184372089344
%e A018900 a(10^4) = 2788273714550169769618891533295908724670464 = 2.788273714550...*10^42
%e A018900 a(10^5) = 3.6341936214780344527466190...*10^134
%e A018900 a(10^6) = 4.5332938264998904048012398...*10^425
%e A018900 a(10^7) = 1.6074616084721302346802429...*10^1346
%e A018900 a(10^8) = 1.4662184497310967196301632...*10^4257
%e A018900 a(10^9) = 2.3037539289782230932863807...*10^13462
%e A018900 a(10^10) = 9.1836811272250798973464436...*10^42571
%e A018900 (End)
%p A018900 a:= n-> (i-> 2^i+2^(n-1-i*(i-1)/2))(floor((sqrt(8*n-1)+1)/2)):
%p A018900 seq(a(n), n=1..100);  # _Alois P. Heinz_, Feb 01 2022
%t A018900 Select[ Range[ 1056 ], (Count[ IntegerDigits[ #, 2 ], 1 ]==2)& ]
%t A018900 Union[Total/@Subsets[2^Range[0,10],{2}]] (* _Harvey P. Dale_, Mar 04 2012 *)
%o A018900 (PARI) for(m=1,9,for(n=0,m-1,print1(2^m+2^n", "))) \\ _Charles R Greathouse IV_, Sep 09 2011
%o A018900 (PARI) is(n)=hammingweight(n)==2 \\ _Charles R Greathouse IV_, Mar 03 2014
%o A018900 (PARI) for(n=0,10^5,if(hammingweight(n)==2,print1(n,", "))); \\ _Joerg Arndt_, Mar 04 2014
%o A018900 (PARI) a(n)= my(t=sqrtint(n*8)\/2); 2^t + 2^(n-1-t*(t-1)/2); \\ _Ruud H.G. van Tol_, Nov 30 2024
%o A018900 (Haskell)
%o A018900 a018900 n = a018900_list !! (n-1)
%o A018900 a018900_list = elemIndices 2 a073267_list  -- _Reinhard Zumkeller_, Mar 07 2012
%o A018900 (C)
%o A018900 unsigned hakmem175(unsigned x) {
%o A018900     unsigned s, o, r;
%o A018900     s = x & -x; r = x + s;
%o A018900     o = x ^ r;  o = (o >> 2) / s;
%o A018900     return r | o;
%o A018900 }
%o A018900 unsigned A018900(int n) {
%o A018900     if (n == 1) return 3;
%o A018900     return hakmem175(A018900(n - 1));
%o A018900 } // _Peter Luschny_, Jan 01 2014
%o A018900 (Smalltalk)
%o A018900 distinctPowersOf: b
%o A018900   "Version 1: Answers the n-th number of the form b^i + b^j, i>j>=0, where n is the receiver.
%o A018900   b > 1 (b = 2, for this sequence).
%o A018900   Usage: n distinctPowersOf: 2
%o A018900   Answer: a(n)"
%o A018900   | n i j |
%o A018900   n := self.
%o A018900   i := (8*n - 1) sqrtTruncated + 1 // 2.
%o A018900   j := n - (i*(i - 1)/2) - 1.
%o A018900   ^(b raisedToInteger: i) + (b raisedToInteger: j)
%o A018900 [by _Hieronymus Fischer_, Apr 20 2014]
%o A018900 ------------
%o A018900 (Smalltalk)
%o A018900 distinctPowersOf: b
%o A018900   "Version 2: Answers an array which holds the first n numbers of the form b^i + b^j, i>j>=0, where n is the receiver. b > 1 (b = 2, for this sequence).
%o A018900   Usage: n distinctPowersOf: 2
%o A018900   Answer: #(3 5 6 9 10 12 ...) [first n terms]"
%o A018900   | k p q terms |
%o A018900   terms := OrderedCollection new.
%o A018900   k := 0.
%o A018900   p := b.
%o A018900   q := 1.
%o A018900   [k < self] whileTrue:
%o A018900          [[q < p and: [k < self]] whileTrue:
%o A018900                    [k := k + 1.
%o A018900                    terms add: p + q.
%o A018900                    q := b * q].
%o A018900          p := b * p.
%o A018900          q := 1].
%o A018900   ^terms as Array
%o A018900 [by _Hieronymus Fischer_, Apr 20 2014]
%o A018900 ------------
%o A018900 (Smalltalk)
%o A018900 floorDistinctPowersOf: b
%o A018900   "Answers an array which holds all the numbers b^i + b^j < n, i>j>=0, where n is the receiver.
%o A018900   b > 1 (b = 2, for this sequence).
%o A018900   Usage: n floorDistinctPowersOf: 2
%o A018900   Answer: #(3 5 6 9 10 12 ...) [all terms < n]"
%o A018900   | a n p q terms |
%o A018900   terms := OrderedCollection new.
%o A018900   n := self.
%o A018900   p := b.
%o A018900   q := 1.
%o A018900   a := p + q.
%o A018900   [a < n] whileTrue:
%o A018900          [[q < p and: [a < n]] whileTrue:
%o A018900                    [terms add: a.
%o A018900                    q := b * q.
%o A018900                    a := p + q].
%o A018900          p := b * p.
%o A018900          q := 1.
%o A018900          a := p + q].
%o A018900   ^terms as Array
%o A018900 [by _Hieronymus Fischer_, Apr 20 2014]
%o A018900 ------------
%o A018900 (Smalltalk)
%o A018900 invertedDistinctPowersOf: b
%o A018900   "Given a number m which is a distinct power of b, this method answers the index n such that there are uniquely defined i>j>=0 for which b^i + b^j = m, where m is the receiver;  b > 1 (b = 2, for this sequence).
%o A018900   Usage: m invertedDistinctPowersOf: 2
%o A018900   Answer: n such that a(n) = m, or, if no such n exists, min (k | a(k) >= m)"
%o A018900   | n i j k m |
%o A018900   m := self.
%o A018900   i := m integerFloorLog: b.
%o A018900   j := m - (b raisedToInteger: i) integerFloorLog: b.
%o A018900   n := i * (i - 1) / 2 + 1 + j.
%o A018900   ^n
%o A018900 [by _Hieronymus Fischer_, Apr 20 2014]
%o A018900 (Python)
%o A018900 print([n for n in range(1, 3001) if bin(n)[2:].count("1")==2]) # _Indranil Ghosh_, Jun 03 2017
%o A018900 (Python)
%o A018900 A018900_list = [2**a+2**b for a in range(1,10) for b in range(a)] # _Chai Wah Wu_, Jan 24 2021
%o A018900 (Python)
%o A018900 from math import isqrt, comb
%o A018900 def A018900(n): return (1<<(m:=isqrt(n<<3)+1>>1))+(1<<(n-1-comb(m,2))) # _Chai Wah Wu_, Oct 30 2024
%Y A018900 Cf. A000120, A001969, A048639, A048645, A057168.
%Y A018900 Cf. A000217, A179951, A187813, A239708.
%Y A018900 Cf. A000079, A014311, A014312, A014313, A023688, A023689, A023690, A023691 (Hamming weight = 1, 3, 4, ..., 9).
%Y A018900 Sum of base-b digits equal b: A226636 (b = 3), A226969 (b = 4), A227062 (b = 5), A227080 (b = 6), A227092 (b = 7), A227095 (b = 8), A227238 (b = 9), A052224 (b = 10). - _M. F. Hasler_, Dec 23 2016
%K A018900 nonn,easy,nice,tabl,look
%O A018900 1,1
%A A018900 Jonn Dalton (jdalton(AT)vnet.ibm.com), Dec 11 1996
%E A018900 Edited by _M. F. Hasler_, Dec 23 2016