De Polignac numbers: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) (Added Perl) |
|||
Line 489: | Line 489: | ||
The 10,000th: 273421 |
The 10,000th: 273421 |
||
</pre> |
</pre> |
||
=={{header|Perl}}== |
|||
{{libheader|ntheory}} |
|||
<syntaxhighlight lang="perl" line>use v5.36; |
|||
use bigint; |
|||
use ntheory <is_prime vecmax vecany logint>; |
|||
sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r } |
|||
sub table ($c, @V) { my $t = $c * (my $w = 2 + vecmax map { length } @V); ( sprintf( ('%'.$w.'s')x@V, @V) ) =~ s/.{1,$t}\K/\n/gr } |
|||
my ($n, @D) = (3, 1); |
|||
while ($n++) { |
|||
next unless $n % 2; |
|||
next if vecany { is_prime($n - 2**$_) } 1 .. logint $n, 2; |
|||
push @D, comma $n; |
|||
last if 10_000 == @D; |
|||
} |
|||
say "First fifty de Polignac numbers:\n" . table 10, @D[0..49]; |
|||
say 'One thousandth: ' . $D[ 999]; |
|||
say 'Ten thousandth: ' . $D[9999];</syntaxhighlight> |
|||
{{out}} |
|||
<pre style="height:20ex">First fifty de Polignac numbers: |
|||
1 127 149 251 331 337 373 509 599 701 |
|||
757 809 877 905 907 959 977 997 1,019 1,087 |
|||
1,199 1,207 1,211 1,243 1,259 1,271 1,477 1,529 1,541 1,549 |
|||
1,589 1,597 1,619 1,649 1,657 1,719 1,759 1,777 1,783 1,807 |
|||
1,829 1,859 1,867 1,927 1,969 1,973 1,985 2,171 2,203 2,213 |
|||
One thousandth: 31,941 |
|||
Ten thousandth: 273,421</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |