Anonymous user
Semiprime: Difference between revisions
→{{header|Perl}}: Switch to ntheory, modify the shortcut example a little.
m (→{{header|Icon}} and {{header|Unicon}}: {{Out}}) |
(→{{header|Perl}}: Switch to ntheory, modify the shortcut example a little.) |
||
Line 528:
=={{header|Perl}}==
{{libheader|ntheory}}
<tt>factor</tt> in scalar context gives the number of factors (like <tt>bigomega</tt> in Pari/GP and <tt>PrimeOmega</tt> in Mathematica).
<lang perl>use
print join(" ", grep { scalar factor($_) == 2 } 1..100),"\n";
print join(" ", grep { scalar factor($_) == 2 } 1675..1681),"\n";
Line 538 ⟶ 539:
4 1679 1234567 900660121</pre>
Following Pari/GP's example, for inputs over 10^10 or so, we can save some time by
<lang perl>
sub issemi {
my $n = shift;
return 0 if @p > 2;
return !!is_prime($p[1]) if @p == 2;
}
2 == factor($n);
}</lang>
|