Jump to content

Pierpont primes: Difference between revisions

Added Wren
(Added Wren)
Line 1,968:
1000th Pierpont prime of the 1st kind: 69269314716439690250482558089997110961545818230232043107188537422260188701607997086273960899938499201024414931399264696270849
1000th Pierpont prime of the 2nd kind: 1308088756227965581249669045506775407896673213729433892383353027814827286537163695213418982500477392209371001259166465228280492460735463423
</pre>
 
=={{header|Wren}}==
{{trans|Go}}
{{libheader|Wren-big}}
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
The 3-smooth version. Just the first 250 - a tolerable 14 seconds or so on my machine.
<lang ecmascript>import "/big" for BigInt
import "/math" for Math
import "/fmt" for Fmt
 
var pierpont = Fn.new { |n, first|
var p = [ List.filled(n, null), List.filled(n, null) ]
for (i in 0...n) {
p[0][i] = BigInt.zero
p[1][i] = BigInt.zero
}
p[0][0] = BigInt.two
var count = 0
var count1 = 1
var count2 = 0
var s = [BigInt.one]
var i2 = 0
var i3 = 0
var k = 1
while (count < n) {
var n2 = s[i2] * 2
var n3 = s[i3] * 3
var t
if (n2 < n3) {
t = n2
i2 = i2 + 1
} else {
t = n3
i3 = i3 + 1
}
if (t > s[k-1]) {
s.add(t.copy())
k = k + 1
t = t.inc
if (count1 < n && t.isProbablePrime(5)) {
p[0][count1] = t.copy()
count1 = count1 + 1
}
t = t - 2
if (count2 < n && t.isProbablePrime(5)) {
p[1][count2] = t.copy()
count2 = count2 + 1
}
count = Math.min(count1, count2)
}
}
return p
}
 
var start = System.clock
var p = pierpont.call(250, true)
System.print("First 50 Pierpont primes of the first kind:")
for (i in 0...50) {
Fmt.write("$8i ", p[0][i])
if ((i-9)%10 == 0) System.print()
}
System.print("\nFirst 50 Pierpont primes of the second kind:")
for (i in 0...50) {
Fmt.write("$8i ", p[1][i])
if ((i-9)%10 == 0) System.print()
}
 
System.print("\n250th Pierpont prime of the first kind: %(p[0][249])")
System.print("\n250th Pierpont prime of the second kind: %(p[1][249])")
System.print("Took %(System.clock - start)")</lang>
 
{{out}}
<pre>
First 50 Pierpont primes of the first kind:
2 3 5 7 13 17 19 37 73 97
109 163 193 257 433 487 577 769 1153 1297
1459 2593 2917 3457 3889 10369 12289 17497 18433 39367
52489 65537 139969 147457 209953 331777 472393 629857 746497 786433
839809 995329 1179649 1492993 1769473 1990657 2654209 5038849 5308417 8503057
 
First 50 Pierpont primes of the second kind:
2 3 5 7 11 17 23 31 47 53
71 107 127 191 383 431 647 863 971 1151
2591 4373 6143 6911 8191 8747 13121 15551 23327 27647
62207 73727 131071 139967 165887 294911 314927 442367 472391 497663
524287 786431 995327 1062881 2519423 10616831 17915903 18874367 25509167 30233087
 
250th Pierpont prime of the first kind: 62518864539857068333550694039553
 
250th Pierpont prime of the second kind: 4111131172000956525894875083702271
</pre>
 
9,488

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.