Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,9 @@
|
|||
use Math::Prime::Util qw(nth_prime prime_count primes);
|
||||
# Direct solutions.
|
||||
# primes([start],end) returns an array reference with all primes in the range
|
||||
# prime_count([start],end) uses sieving or LMO to return fast prime counts
|
||||
# nth_prime(n) does just that. It runs quite fast for native size inputs.
|
||||
say "First 20: ", join(" ", @{primes(nth_prime(20))});
|
||||
say "Between 100 and 150: ", join(" ", @{primes(100,150)});
|
||||
say prime_count(7700,8000), " primes between 7700 and 8000";
|
||||
say "${_}th prime: ", nth_prime($_) for map { 10**$_ } 1..8;
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
use Math::Prime::Util "prime_iterator_object";
|
||||
my $it = prime_iterator_object;
|
||||
say "First 20: ", join(" ", map { $it->iterate() } 1..20);
|
||||
$it->seek_to_value(100);
|
||||
print "Between 100 and 150:";
|
||||
print " ", $it->iterate() while $it->value() <= 150;
|
||||
print "\n";
|
||||
$it->seek_to_value(7700);
|
||||
my $c = 0;
|
||||
$c++ while $it->iterate() <= 8000;
|
||||
say "$c primes between 7700 and 8000";
|
||||
say "${_}th prime: ", $it->ith($_) for map { 10**$_ } 1..8;
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
use Math::Prime::Util qw/forprimes/;
|
||||
use Math::Prime::Util::PrimeArray;
|
||||
tie my @primes, 'Math::Prime::Util::PrimeArray';
|
||||
|
||||
say "First 20: @primes[0..19]"; # Slice from the tied array
|
||||
print "Between 100 and 150: "; forprimes { print " $_"; } 100,150; print "\n";
|
||||
# Count with forprimes
|
||||
my $c = 0;
|
||||
forprimes { $c++ } 7700,8000;
|
||||
print "$c primes between 7700 and 8000\n";
|
||||
# The tied array tries to do the right thing -- sieve a window if it sees
|
||||
# forward or backward iteration, and nth_prime if it looks like random access.
|
||||
say "${_}th prime: ", $primes[$_-1] for map { 10**$_ } 1..8;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
use bigint;
|
||||
use Math::Prime::Util qw/forprimes prime_get_config/;
|
||||
warn "No GMP, expect slow results\n" unless prime_get_config->{gmp};
|
||||
my $n = 10**200;
|
||||
forprimes { say $_-$n } $n,$n+1000;
|
||||
Loading…
Add table
Add a link
Reference in a new issue