%I #28 May 14 2017 12:02:07
%S 2,5,11,17,19,23,47,67,71,79,131,191,257,263,271,383,1031,1039,1087,
%T 1151,1279,2063,2111,4099,4111,4127,4159,5119,6143,8447,16447,20479,
%U 32771,32783,32831,33023,33791,65537,65539,65543,65551,65599,66047,73727,81919,262147,262151,262271,262399,263167
%N Primes of the form m = 2^i + 2^j - 1, where i > j >= 0.
%C Numbers m such that b = 2 is the only base such that the base-b digital sum of m + 1 is equal to b.
%C Example: 5 + 1 = 110_2 which implies ds_2(5 + 1) = 2 = b, where ds_b = digital sum in base-b. However, ds_3(6) = 2 <> 3, ds_4(6) = 3 <> 4, ds_5(6) = 2 <> 5, ds_6(6) = 1 <> 6. For all other bases > 6 we have ds_b(6) = 6 <> b. It follows that b = 2 is the only such base.
%C The base-2 representation of a term 2^i + 2^j - 1 has a base-2 digital sum of 1 + j.
%C In base-2 representation the first terms are 10, 101, 1011, 10001, 10011, 10111, 101111, 1000011, 1000111, 1001111, 10000011, 10111111, 100000001, 100000111, 100001111, 101111111, 10000000111, 10000001111, 10000111111, 10001111111, ...
%C Numbers m = 2^i + 2^j - 1 with odd i and j are not terms. Example: 10239 = 2^13 + 2^11 - 1 is not a prime.
%H Hieronymus Fischer, <a href="/A239712/b239712.txt">Table of n, a(n) for n = 1..250</a>
%F a(n) = A239708(n) - 1.
%F a(n+1) = min(A018900(k) > a(n)| A018900(k) - 1 is prime, k >= 1) - 1.
%e a(1) = 2, since 2 = 2^1 + 2^0 - 1 is prime.
%e a(5) = 19, since 19 = 2^4 + 2^2 - 1 is prime.
%t Select[Union[Total/@(2^#&/@Subsets[Range[0,20],{2}])-1],PrimeQ] (* _Harvey P. Dale_, Aug 08 2014 *)
%o (Smalltalk)
%o A239712
%o "Answers the n-th term of A239712.
%o Usage: n A239712
%o Answer: a(n)"
%o | a b i k m p q terms |
%o terms := OrderedCollection new.
%o b := 2.
%o p := 1.
%o k := 0.
%o m := 0.
%o [k < self] whileTrue:
%o [m := m + 1.
%o p := b * p.
%o q := 1.
%o i := 0.
%o [i < m and: [k < self]] whileTrue:
%o [i := i + 1.
%o a := p + q - 1.
%o a isPrime
%o ifTrue:
%o [k := k + 1.
%o terms add: a].
%o q := b * q]].
%o ^terms at: self
%o [by _Hieronymus Fischer_, Apr 22 2014]
%o -----------
%o (Smalltalk)
%o floorPrimesWhichAreDistinctPowersOf: b withOffset: d
%o "Answers an array which holds the primes < n that obey b^i + b^j + d, i>j>=0,
%o where n is the receiver. b > 1 (here: b = 2, d = -1).
%o Uses floorDistinctPowersOf: from A018900
%o Usage:
%o n floorPrimesWhichAreDistinctPowersOf: b withOffset: d
%o Answer: #(2 5 11 17 19 23 ...) [terms < n]"
%o ^((self - d floorDistinctPowersOf: b)
%o collect: [:i | i + d]) select: [:i | i isPrime]
%o [by _Hieronymus Fischer_, Apr 22 2014]
%o ------------
%o (Smalltalk)
%o primesWhichAreDistinctPowersOf: b withOffset: d
%o "Answers an array which holds the n primes of the form b^i + b^j + d, i>j>=0, where n is the receiver.
%o Direct calculation by scanning b^i + b^j + d in increasing order and selecting terms which are prime.
%o b > 1; this sequence: b = 2, d = 1.
%o Usage:
%o n primesWhichAreDistinctPowersOf: b withOffset: d
%o Answer: #(2 5 11 17 19 23 ...) [a(1) ... a(n)]"
%o | a k p q terms n |
%o terms := OrderedCollection new.
%o n := self.
%o k := 0.
%o p := b.
%o [k < n] whileTrue:
%o [q := 1.
%o [q < p and: [k < n]] whileTrue:
%o [a := p + q + d.
%o a isPrime
%o ifTrue:
%o [k := k + 1.
%o terms add: a].
%o q := b * q].
%o p := b * p].
%o ^terms asArray
%o [by _Hieronymus Fischer_, Apr 22 2014]
%Y Cf. A007953, A018900, A081091, A008864, A187813.
%Y Cf. A239703, A239708, A239709, A239713 - A239720.
%K nonn
%O 1,1
%A _Hieronymus Fischer_, Mar 28 2014 and Apr 22 2014
%E Examples moved from Maple field to Examples field by _Harvey P. Dale_, Aug 08 2014