On Sat Nov 24 02:47:14 2012, sflitman wrote:
Show quoted text> my $sieve=Math::Prime::FastSieve->new( 5_000_000 );
> my $num_found=$sieve->count_num();
> # $num_found == 1, should be 34851
sorry that should be count_sieve, not count_num
This is odd, testing that function alone shows it works, but it fails
when I tried to test it from the synopsis with the enclosed file.
c:\> perl -MMath::Prime::FastSieve -e "my
$sieve=Math::Prime::FastSieve::Sieve->new(5_000_000); print $sieve-
Show quoted text>count_sieve"
348513
That's what I get for typing instead of cut and paste!
By the way, it doesn't fail for a sieve of 5_000_000_000 on my Core i7
laptop with 8G RAM, it reports 36500086
This module is a tour de force, and it ran on Windows 7 under Strawberry
Perl no less. Thanks, you've really opened my eyes to what is possible
with Inline::CPP!
SSF
#!/usr/bin/perl
# SSF 112412 - test Math::Prime::FastSieve
use Math::Prime::FastSieve;
# Create a new sieve and flag all primes less or equal to n.
my $sieve = Math::Prime::FastSieve::Sieve->new( 5_000_000 );
# Obtain a ref to an array containing all primes <= 5 Million.
my $aref = $sieve->primes( 5_000_000 );
print "Number of primes up to 5,000,000: ",scalar @$aref,"\n";
# Obtain a ref to an array containing all primes >= 5, and <= 16.
my $aref = $sieve->ranged_primes( 5, 16 );
print "Primes between 5 and 16: ",join(',',@$aref),"\n";
# Query the sieve: Is 17 prime? Return a true or false value.
my $result = $sieve->isprime( 17 );
print "Is 17 prime: ",$result ? "Yes" : "No","\n";
# Get the value of the nearest prime less than or equal to 42.
my $less_or_equal = $sieve->nearest_le( 42 );
print "Nearest prime less than or equal to 42: ",$less_or_equal,"\n";
# Get the value of the nearest prime greater than or equal to 42.
my $greater_or_equal = $sieve->nearest_ge( 42 );
print "Nearest prime greater than or equal to 42: ",$greater_or_equal,"\n";
# Count how many primes exist within the sieve (ie, count all primes less
# than or equal to 5 Million, assuming we instantiated the sieve with
# Math::Prime::FastSieve::Sieve->new( 5_000_000 );.
my $num_found = $sieve->count_sieve();
print "How many primes in sieve: ",$num_found,"\n";
# Count how many primes fall between 1 and 42 inclusive.
my $quantity_le = $sieve->count_le( 42 );
print "How many primes fall between 1 and 42 inclusive: ",$quantity_le,"\n";
# Return the value of the 42nd prime number.
my $forty_second_prime = $sieve->nth_prime( 42 );
print "The 42nd prime number is ",$forty_second_prime,"\n";
exit;