Super-Poulet numbers: Difference between revisions

Added Perl
(Added Perl)
Line 77:
The first super-Poulet number over 10 million is the 317th one, which is 10031653
</pre>
 
=={{header|Perl}}==
{{libheader|ntheory}}
<syntaxhighlight lang="perl" line>use v5.36;
use experimental <builtin for_list>;
use List::AllUtils <firstidx all>;
use ntheory <is_prime divisors powmod>;
 
sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r }
 
my @poulet = grep { !is_prime($_) && (1 == powmod 2, $_ - 1, $_) } 2 .. 1.1e7;
my @super_poulet = grep { all { 2 == powmod 2, $_, $_ } grep { $_ > 1 } divisors $_ } @poulet;
 
say "First 20 super-Poulet numbers:\n" . join ' ', @super_poulet[0..19];
for my($i,$j) (1, 1e6, 10, 1e7) {
my $index = firstidx { $_ > $j } @super_poulet;
say "\nIndex and value of first super-Poulet greater than $i million:";
say "#@{[1+$index]} is " . comma $super_poulet[$index];
}</syntaxhighlight>
{{out}}
<pre>First 20 super-Poulet numbers:
341 1387 2047 2701 3277 4033 4369 4681 5461 7957 8321 10261 13747 14491 15709 18721 19951 23377 31417 31609
 
Index and value of first super-Poulet greater than 1 million:
#109 is 1,016,801
 
Index and value of first super-Poulet greater than 10 million:
#317 is 10,031,653</pre>
 
=={{header|Phix}}==
2,392

edits