in reply to Re^2: Number functions I have lying around
in thread Number functions I have lying around

A modest improvement in speed may be obtained if one implements the wheel.

For example (the modulus is relatively cheap in perl):

sub primes { my $n = shift; return if $n < 2; my @primes = (2); I: for my $i (3 .. $n) { next unless 0x208a28aa & (1 << $i % 30); my $sqrt = int sqrt $i; for my $p (@primes) { next I unless $i % $p; last if $p > $sqrt; } push @primes, $i; } return @primes }

Replies are listed 'Best First'.
Re^4: Number functions I have lying around
by Anonymous Monk on Apr 02, 2015 at 16:55 UTC

    Actually, it's 0x208a2882, but you have to initialize primes to (2, 3, 5) then..