NumSeq/TotientCumulative.pm

filter: Statementstmt 96.6% 58 / 60 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 15 / 15 Podpod 100% 4 / 4 totaltotal 95.4% 83 / 87 CC 6 SCAR 6.5
CC
6
Cov
94%
pred
4.0
ith
3.1
BEGIN
1.0
CRAP 1.9
« NumSeq/Triangular.pm ↑ Summary NumSeq/StarNumbers.pm »
1 # Copyright 2011, 2012, 2013, 2014, 2016, 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  
20 # Untouchables, not sum of proper divisors of any other integer
21 # p*q sum S=1+p+q
22 # so sums up to hi need factorize to (hi^2)/4
23 #
24  
25  
26 package Math::NumSeq::TotientCumulative;
27 2 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 2 ▶use vars '$VERSION', '@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 $VERSION = 75;
32 2 ▶use Math::NumSeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 @ISA = ('Math::NumSeq');
34 2 *_is_infinite = \&Math::NumSeq::_is_infinite;
35  
36 2 ▶use Math::NumSeq::Totient;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 2 *_totient = \&Math::NumSeq::Totient::_totient;
38  
39  
40 # uncomment this to run the ### lines
41 #use Devel::Comments;
42  
43 # use constant name => Math::NumSeq::__('Totient Cumulative');
44 2 ▶use constant description => Math::NumSeq::__('Cumulative totient(1..n).');
Subroutine BEGIN: called CC=1 SCAR=0.0
45 2 ▶use constant default_i_start => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 2 ▶use constant values_min => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 2 ▶use constant characteristic_increasing => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 2 ▶use constant characteristic_integer => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 # cf A015614 totient cumulative + 1
51 2 ▶use constant oeis_anum => 'A002088';
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 4 ▶sub rewind {
Subroutine rewind: called CC=1 SCAR=0.0
Pod documented
54 4 my ($self) = @_;
55 4 $self->{'i'} = $self->i_start;
56 4 $self->{'sum'} = 0;
57 }
58 24 ▶sub next {
Subroutine next: called CC=1 SCAR=0.0
Pod documented
59 24 my ($self) = @_;
60 24 my $i = $self->{'i'}++;
61 24 return ($i, $self->{'sum'} += _totient($i));
62 }
63  
64 39 ▶sub ith {
Subroutine ith: called CC=3 SCAR=11.3
Pod documented
65 39 my ($self, $i) = @_;
66 ### TotientCumulative ith(): $i
67  
68 39 ▶ if (_is_infinite($i)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_infinite($i)) 0 39 39
69 0 return $i;
70 }
71 39 my $sum = 0;
72 39 foreach my $n (1 .. $i) {
73 287 $sum += _totient($n);
74 }
75 39 return $sum;
76 }
77  
78 97 ▶sub pred {
Subroutine pred: called CC=4 SCAR=13.9
Pod documented
79 97 my ($self, $value) = @_;
80 ### TotientCumulative pred(): $value
81  
82 97 ▶ if (_is_infinite($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_infinite($value)) 0 97 97
83 0 return 0;
84 }
85 97 my $sum = 0;
86 97 for (my $n = 0; ; $n++) {
87 912 ▶ if ($sum == $value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sum == $value) 24 888 912
88 24 return 1;
89 }
90 888 ▶ if ($sum > $value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sum > $value) 73 815 888
91 73 return 0;
92 }
93 815 $sum += _totient($n);
94 }
95 }
96  
97 2 1;
98 __END__
« NumSeq/Triangular.pm ↑ Summary NumSeq/StarNumbers.pm »