NumSeq/DivisorCount.pm

filter: Statementstmt 100% 59 / 59 Branchbran 87.5% 7 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 15 / 15 Podpod 100% 4 / 4 totaltotal 94.5% 86 / 91 CC 6 SCAR 7.5
CC
6
Cov
96%
ith
5.0
pred
2.3
BEGIN
1.0
CRAP 2.1
« NumSeq/HappySteps.pm ↑ Summary NumSeq/PrimeIndexOrder.pm »
1 # Copyright 2011, 2012, 2013, 2014, 2016, 2017, 2019, 2020 Kevin Ryde
2  
3 # This file is part of Math-NumSeq.
4 #
5 # Math-NumSeq is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 3, or (at your option) any later
8 # version.
9 #
10 # Math-NumSeq is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.
17  
18  
19 package Math::NumSeq::DivisorCount;
20 2 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 ▶use vars '$VERSION','@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 $VERSION = 75;
25  
26 2 ▶use Math::NumSeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use Math::NumSeq::Base::IterateIth;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 @ISA = ('Math::NumSeq::Base::IterateIth',
29 'Math::NumSeq');
30  
31 2 ▶use Math::NumSeq::PrimeFactorCount;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 *_prime_factors = \&Math::NumSeq::PrimeFactorCount::_prime_factors;
33  
34  
35 # use constant name => Math::NumSeq::__('Divisor Count');
36 2 ▶use constant description => Math::NumSeq::__('Count of divisors of i (including 1 and i).');
Subroutine BEGIN: called CC=1 SCAR=0.0
37 2 ▶use constant i_start => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 ▶use constant characteristic_count => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 2 ▶use constant characteristic_smaller => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 2 ▶use constant characteristic_increasing => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42  
43 # "proper" divisors just means 1 less in each value, not sure much use for
44 # that.
45 #
46 # n itself -- proper, or not
47 # 1 -- proper, or not
48 # square, non-square
49 #
50 # use constant parameter_info_array =>
51 # [ { name => 'divisor_type',
52 # display => Math::NumSeq::__('Divisor Type'),
53 # type => 'enum',
54 # choices => ['all','proper'], # ,'propn1'
55 # default => 'all',
56 # # description => Math::NumSeq::__(''),
57 # },
58 # ];
59  
60  
61 2 my %values_min = (all => 1,
62 proper => 0,
63 propn1 => 0);
64 1 ▶sub values_min {
Subroutine values_min: called CC=1 SCAR=0.0
Pod documented
65 1 my ($self) = @_;
66 # or values_min=0 if i_start=0
67 1 return 1; # $values_min{$self->{'divisor_type'}};
68 }
69  
70 #------------------------------------------------------------------------------
71 # cf A032741 - 1 <= d < n starting n=0
72 # A147588 - 1 < d < n starting n=1
73 #
74 # A006218 - cumulative count of divisors
75 # A002541 - cumulative proper divisors
76 #
77 # A001227 - count odd divisors
78 # A001826 - count 4k+1 divisors
79 # A038548 - count divisors <= sqrt(n)
80 # A070824 - proper divisors starting n=2
81 # A002182 - number with new highest number of divisors
82 # A002183 - that count of divisors
83 # A001876 - count 5k+1 divisors
84 # A001877 - count 5k+2 divisors
85 # A001878 - count 5k+3 divisors
86 # A001899 - count 5k+4 divisors
87 #
88 # A028422 - count of ways to factorize
89 # A033834 - n with new high count factorizations
90 # A033833 - highly factorable
91 #
92 # A056595 - count non-square divisors
93 # A046951 - count square divisors
94 # A013936 - cumulative count square divisors
95 # A137518 - same divisor count as n, and > a(n-1) so increasing
96 #
97 1 ▶sub oeis_anum {
Subroutine oeis_anum: called CC=1 SCAR=0.0
Pod documented
98 1 my ($self) = @_;
99 1 return 'A000005';
100 # OEIS-Catalogue: A000005
101  
102 # my %oeis_anum = (all => 'A000005', # all divisors starting n=1
103 # # proper => 'A032741', # starts n=0 ...
104 # # propn1 => 'A147588',
105 # );
106 # return $oeis_anum{$self->{'divisor_type'}};
107 }
108  
109  
110 #------------------------------------------------------------------------------
111 69 ▶sub ith {
Subroutine ith: called CC=5 SCAR=16.1
Pod documented
112 69 my ($self, $i) = @_;
113  
114 69 $i = abs($i);
115 69 ▶ if ($i == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0) 1 68 69
116 1 return 0;
117 }
118  
119 # If i = p^a * q^b * ... then divisorcount = (a+1)*(b+1)*...
120 # which is each possible power p^0, p^1, ..., p^a of each prime,
121 # including all zeros p^0*q^0*... = 1 and p^a*q^b*... itself.
122 #
123 # If i is a primorial 2*3*5*7*13*... with k primes then divisorcount=2^k
124 # so the $value product can become a bignum if $i is a bignum.
125  
126 68 my ($good, @primes) = _prime_factors($i);
127 68 ▶ return undef unless $good;
Branch: 1 branch
BranchTrueFalseTotal
unless $good 0 68 68
128  
129 68 my $value = ($i*0) + 1; # inherit possible bignum
130 68 my $prev = 0;
131 68 my $dcount = 1;
132 68 ▶ while (my $p = shift @primes) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $p = shift @primes) 86 68 154
133 86 ▶ if ($p == $prev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p == $prev) { } 13 73 86
134 13 $dcount++;
135 } else {
136 73 $value *= $dcount;
137 73 $dcount = 2;
138 73 $prev = $p;
139 }
140 }
141 68 return $value * $dcount;
142  
143 # if ($self->{'divisor_type'} eq 'propn1') {
144 # if ($ret <= 2) {
145 # return 0;
146 # }
147 # $ret -= 2;
148 # }
149 }
150  
151 7 ▶sub pred {
Subroutine pred: called CC=2 SCAR=8.1
Pod documented
152 7 my ($self, $value) = @_;
153 7 ▶ return ($value >= 1 && $value == int($value));
Condition33%1/3
$value >= 1 && $value == int $value
!ll&&!rl&&r
007
MC/DC0%0/2
$value >= 1 && $value == int $value
$value >= 1 $value == int $value
Truth table33%1/3
A && B
A= $value >= 1B= $value == int $value
ABresult
0X0
100
111
154 }
155  
156 2 1;
157 __END__
« NumSeq/HappySteps.pm ↑ Summary NumSeq/PrimeIndexOrder.pm »