Anonymous user
Semiprime: Difference between revisions
m
→{{header|Perl}}: Show how we can use the smoothness test from Pari/GP
(+Java) |
m (→{{header|Perl}}: Show how we can use the smoothness test from Pari/GP) |
||
Line 507:
1678 1679 1681
4 1679 1234567 900660121</pre>
Following Pari/GP's example, for inputs over 10^10 or so, we can save some time by using trial division first:
<lang perl>my @_small_primes = @{primes(100)};
sub issemi {
my $n = shift;
for my $p (@_small_primes) { return !!is_prime($n/$p) unless $n % $p; }
2 == factor($n);
}</lang>
=={{header|Perl 6}}==
|