Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict; # https://rosettacode.org/wiki/Legendre_prime_counting_function
|
||||
use warnings;
|
||||
no warnings qw(recursion);
|
||||
use ntheory qw( nth_prime prime_count );
|
||||
|
||||
my (%cachephi, %cachepi);
|
||||
|
||||
sub phi
|
||||
{
|
||||
return $cachephi{"@_"} //= do {
|
||||
my ($x, $aa) = @_;
|
||||
$aa <= 0 ? $x : phi($x, $aa - 1) - phi(int $x / nth_prime($aa), $aa - 1) };
|
||||
}
|
||||
|
||||
sub pi
|
||||
{
|
||||
return $cachepi{$_[0]} //= do {
|
||||
my $n = shift;
|
||||
$n < 2 ? 0 : do{ my $aa = pi(int sqrt $n); phi($n, $aa) + $aa - 1 } };
|
||||
}
|
||||
|
||||
print "e n Legendre ntheory\n",
|
||||
"- - -------- -------\n";
|
||||
for (1 .. 9)
|
||||
{
|
||||
printf "%d %12d %10d %10d\n", $_, 10**$_, pi(10**$_), prime_count(10**$_);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue