Wagstaff primes: Difference between revisions

Added Perl
(Added Perl)
Line 119:
31 715827883
43 2932031007403</syntaxhighlight>
=={{header|Perl}}==
First 20 terms are very fast, and 30 terms in just the time it takes to make a cup of coffee! (caveat: IFF you allow for the travel time of a flight to Hawaii to pick up some nice Kona beans first). Seriously, don't try this at home; <tt>bigint</tt> is mandatory here, which makes it glacially slow...
 
{{libheader|ntheory}}
<syntaxhighlight lang="perl" line>use v5.36;
use bigint;
use ntheory 'is_prime';
 
sub abbr ($d) { my $l = length $d; $l < 61 ? $d : substr($d,0,30) . '..' . substr($d,-30) . " ($l digits)" }
 
my($p,@W) = 2;
until (@W == 30) {
next unless 0 != ++$p % 2;
push @W, $p if is_prime($p) and is_prime((2**$p + 1)/3)
}
 
printf "%2d: %5d - %s\n", $_+1, $W[$_], abbr( (2**$W[$_] + 1) / 3) for 0..$#W;</syntaxhighlight>
{{out}}
<pre> 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 - 768614336404564651
12: 79 - 201487636602438195784363
13: 101 - 845100400152152934331135470251
14: 127 - 56713727820156410577229101238628035243
15: 167 - 62357403192785191176690552862561408838653121833643
16: 191 - 1046183622564446793972631570534611069350392574077339085483
17: 199 - 267823007376498379256993682056860433753700498963798805883563
18: 313 - 556246623937737000623703569314..370363869220418099018130434731 (94 digits)
19: 347 - 955624423329196463171175373042..686867002917439712921903606443 (104 digits)
20: 701 - 350675726769891567149399325525..838589548478180862167823854251 (211 digits)
21: 1709 - 961925272487010690059185752191..922686975212036857299070528171 (514 digits)
22: 2617 - 208150470990263232578066751439..039652079499645847933435947691 (788 digits)
23: 3539 - 737960982013072251717827114247..199733732972086304686486497963 (1065 digits)
24: 5807 - 401849623734300407681642626119..205019459748642466686663568043 (1748 digits)
25: 10501 - 435374724597165148564719869736..420302813453630340431558126251 (3161 digits)
26: 10691 - 683222859828090890299791032836..667114601633276209259644365483 (3218 digits)
27: 11279 - 692149388152358271880180910368..100257387805213081084271176363 (3395 digits)
28: 12391 - 385083595083686155852404805983..016288359843183967789680077483 (3730 digits)
29: 14479 - 136831460986221458568512534755..409643689259682678801865288363 (4359 digits)
30: 42737 - 438332262203687089339145725663..235631349264841566953606392491 (12865 digits)</pre>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
2,392

edits