Super-Poulet numbers: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (New draft task and Raku entry) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: off-by-one error) |
||
Line 23:
my @poulet = lazy (2..*).hyper(:2000batch).grep: { !.is-prime && (1 == expmod 2, $_ - 1, $_) }
my @super-poulet = @poulet.grep: { all .&divisors.map: { (exp($_, 2) - 2) %% $_ } }
say "First 20 Super-Poulet numbers:\n" ~ @super-poulet[^20].gist;
Line 30:
say "\nIndex and value of first Super-Poulet greater than {$threshold.&cardinal}:";
my $index = @super-poulet.first: * > $threshold, :k;
say "{(1+$index).&ordinal-digit} Super-Poulet number == " ~ @super-poulet[$index].,</lang>
{{out}}
<pre>First 20 Super-Poulet numbers:
Line 36:
Index and value of first Super-Poulet greater than one million:
|
Revision as of 23:17, 16 August 2022
Super-Poulet numbers is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
A Super-Poulet number is a Poulet number (or Fermat pseudoprime to base 2) whose every divisor d evenly divides 2d − 2.
- Task
- Find and display the first 20 Super-Poulet numbers.
- Stretch
- Find and display the index and value of the first Super-Poulet number greater than one million.
- See also
Raku
<lang perl6>use Prime::Factor; use Lingua::EN::Numbers;
my @poulet = lazy (2..*).hyper(:2000batch).grep: { !.is-prime && (1 == expmod 2, $_ - 1, $_) } my @super-poulet = @poulet.grep: { all .&divisors.map: { (exp($_, 2) - 2) %% $_ } }
say "First 20 Super-Poulet numbers:\n" ~ @super-poulet[^20].gist;
my $threshold = 1e6.Int; say "\nIndex and value of first Super-Poulet greater than {$threshold.&cardinal}:"; my $index = @super-poulet.first: * > $threshold, :k; say "{(1+$index).&ordinal-digit} Super-Poulet number == " ~ @super-poulet[$index].,</lang>
- Output:
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 one million: 109th Super-Poulet number == 1,016,801