Wagstaff primes: Difference between revisions
Content deleted Content added
m Minor edit to C++ code |
Added Sidef |
||
(One intermediate revision by one other user not shown) | |||
Line 1,349:
3539
5807
</pre>
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">var iter = Enumerator({|callback|
var p = 2
loop {
var t = ((2**p + 1)/3)
callback([p, t]) if t.is_prime
p.next_prime!
}
})
var n = 1
say "Index Exponent Prime"
say "-"*31
iter.each {|k|
var (e, p) = k...
p = "(#{p.len} digits)" if (n > 10)
say "#{'%5s'%n} #{'%8s'%e} #{'%16s'%p}"
break if (n == 24)
++n
}</syntaxhighlight>
{{out}}
<pre>
Index Exponent Prime
-------------------------------
1 3 3
2 5 11
3 7 43
4 11 683
5 13 2731
6 17 43691
7 19 174763
8 23 2796203
9 31 715827883
10 43 2932031007403
11 61 (18 digits)
12 79 (24 digits)
13 101 (30 digits)
14 127 (38 digits)
15 167 (50 digits)
16 191 (58 digits)
17 199 (60 digits)
18 313 (94 digits)
19 347 (104 digits)
20 701 (211 digits)
21 1709 (514 digits)
22 2617 (788 digits)
23 3539 (1065 digits)
24 5807 (1748 digits)
</pre>
Line 1,358 ⟶ 1,409:
Even so, as far as the stretch goal is concerned, takes around 25 seconds to find the next 14 Wagstaff primes but almost 10 minutes to find the next 19 on my machine (Core i7). I gave up after that.
<syntaxhighlight lang="
import "./gmp" for Mpz
import "./fmt" for Fmt
|