Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Totient-function/Perl/totient-function-1.pl
Normal file
22
Task/Totient-function/Perl/totient-function-1.pl
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
use utf8;
|
||||
binmode STDOUT, ":utf8";
|
||||
|
||||
sub gcd {
|
||||
my ($u, $v) = @_;
|
||||
while ($v) {
|
||||
($u, $v) = ($v, $u % $v);
|
||||
}
|
||||
return abs($u);
|
||||
}
|
||||
|
||||
push @𝜑, 0;
|
||||
for $t (1..10000) {
|
||||
push @𝜑, scalar grep { 1 == gcd($_,$t) } 1..$t;
|
||||
}
|
||||
|
||||
printf "𝜑(%2d) = %3d%s\n", $_, $𝜑[$_], $_ - $𝜑[$_] - 1 ? '' : ' Prime' for 1 .. 25;
|
||||
print "\n";
|
||||
|
||||
for $limit (100, 1000, 10000) {
|
||||
printf "Count of primes <= $limit: %d\n", scalar grep {$_ == $𝜑[$_] + 1} 0..$limit;
|
||||
}
|
||||
13
Task/Totient-function/Perl/totient-function-2.pl
Normal file
13
Task/Totient-function/Perl/totient-function-2.pl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
use utf8;
|
||||
binmode STDOUT, ":utf8";
|
||||
|
||||
use ntheory qw(euler_phi);
|
||||
|
||||
my @𝜑 = euler_phi(0,10000); # Returns list of all values in range
|
||||
|
||||
printf "𝜑(%2d) = %3d%s\n", $_, $𝜑[$_], $_ - $𝜑[$_] - 1 ? '' : ' Prime' for 1 .. 25;
|
||||
print "\n";
|
||||
|
||||
for $limit (100, 1000, 10000) {
|
||||
printf "Count of primes <= $limit: %d\n", scalar grep {$_ == $𝜑[$_] + 1} 0..$limit;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue