login
Primes of the form m = 3^i + 3^j - 1, where i > j >= 0.
3

%I #22 Dec 22 2024 15:57:04

%S 3,11,29,83,89,107,251,269,809,971,2213,2267,6563,6569,6803,8747,

%T 19709,19763,20411,59051,65609,177173,183707,531521,538001,590489,

%U 1594331,1594403,1595051,1596509,4782971,4782977,4783697,14348909,14349149,14526053,14880347

%N Primes of the form m = 3^i + 3^j - 1, where i > j >= 0.

%C The base-3 representation of a term 3^i + 3^j - 1 has base-3 digital sum = 1 + 2*j == 1 (mod 2).

%C In base-3 representation the first terms are 10, 102, 1002, 10002, 10022, 10222, 100022, 100222, 1002222, 1022222, 10000222, 10002222, 100000002, 100000022, 100022222, 102222222, 1000000222, 1000002222, 1000222222, 10000000002, 10022222222, 100000000222, 100022222222, ...

%H Hieronymus Fischer, <a href="/A239713/b239713.txt">Table of n, a(n) for n = 1..131</a> [a(123) corrected by _Georg Fischer_, Dec 22 2024]

%e a(1) = 3, since 3 = 3^1 + 3^0 - 1 is prime.

%e a(5) = 89, since 89 = 3^4 + 3^2 - 1 is prime.

%p select(isprime, [seq(seq(3^i+3^j-1, j=0..i-1), i=1..25)])[]; # _Alois P. Heinz_, Dec 22 2024

%o (Smalltalk)

%o A239713

%o "Answers the n-th term of A239713.

%o Usage: n A239713

%o Answer: a(n)"

%o | a b i j k p q terms |

%o terms := OrderedCollection new.

%o k := 0.

%o b := 3.

%o p := b.

%o i := 1.

%o [k < self] whileTrue:

%o [j := 0.

%o q := 1.

%o [j < i and: [k < self]] whileTrue:

%o [a := p + q - 1.

%o a isPrime

%o ifTrue:

%o [k := k + 1.

%o terms add: a].

%o q := b * q.

%o j := j + 1].

%o i := i + 1.

%o p := b * p].

%o ^terms at: self

%o [by _Hieronymus Fischer_, Apr 14 2014]

%o --------------------

%o (Smalltalk)

%o A239713

%o "Version 2: Answers the n-th term of A239713.

%o Uses distinctPowersOf: b from A018900

%o Usage: n A239713

%o Answer: a(n)”

%o | a k n terms |

%o terms := OrderedCollection new.

%o n := 1.

%o k := 0.

%o [k < self] whileTrue:

%o [(a:= (n distinctPowersOf: 3) - 1)

%o isPrime ifTrue: [k := k + 1.

%o terms add: a].

%o n := n + 1].

%o ^terms at: self

%o [by _Hieronymus Fischer_, Apr 22 2014]

%o -----------

%o (Smalltalk)

%o A239713

%o "Version 3: Answer an array of the first n terms of A239713.

%o Uses method primesWhichAreDistinctPowersOf: b withOffset: d from A239712.

%o Usage: n A239713

%o Answer: #(3 11 29 ... ) [a(1) ... a(n)]”

%o ^self primesWhichAreDistinctPowersOf: 3 withOffset: -1

%o [by _Hieronymus Fischer_, Apr 22 2014]

%Y Cf. A018900, A239709, A239712 (base 2), A239714 (base 4), A239715 (base 5), A239716 (base 6), A239717 (base 7), A239718 (base 8), A239719 (base 9), A239720 (base 10).

%K nonn

%O 1,1

%A _Hieronymus Fischer_, Mar 28 2014