line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2011, 2012, 2013, 2014 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 . |
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
|
|
|
2
|
|
13333
|
use 5.004; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
92
|
|
28
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
81
|
|
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
2
|
|
11
|
use vars '$VERSION', '@ISA'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
142
|
|
31
|
|
|
|
|
|
|
$VERSION = 71; |
32
|
2
|
|
|
2
|
|
663
|
use Math::NumSeq; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
231
|
|
33
|
|
|
|
|
|
|
@ISA = ('Math::NumSeq'); |
34
|
|
|
|
|
|
|
*_is_infinite = \&Math::NumSeq::_is_infinite; |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
2
|
|
3470
|
use Math::NumSeq::Totient; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
106
|
|
37
|
|
|
|
|
|
|
*_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
|
|
|
2
|
|
13
|
use constant description => Math::NumSeq::__('Cumulative totient(1..n).'); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
11
|
|
45
|
2
|
|
|
2
|
|
11
|
use constant i_start => 0; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
79
|
|
46
|
2
|
|
|
2
|
|
9
|
use constant values_min => 0; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
68
|
|
47
|
2
|
|
|
2
|
|
8
|
use constant characteristic_increasing => 1; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
68
|
|
48
|
2
|
|
|
2
|
|
9
|
use constant characteristic_integer => 1; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
70
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# cf A015614 totient cumulative + 1 |
51
|
2
|
|
|
2
|
|
9
|
use constant oeis_anum => 'A002088'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
759
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub rewind { |
54
|
4
|
|
|
4
|
1
|
747
|
my ($self) = @_; |
55
|
4
|
|
|
|
|
33
|
$self->{'i'} = $self->i_start; |
56
|
4
|
|
|
|
|
17
|
$self->{'sum'} = 0; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
sub next { |
59
|
24
|
|
|
24
|
1
|
933
|
my ($self) = @_; |
60
|
24
|
|
|
|
|
40
|
my $i = $self->{'i'}++; |
61
|
24
|
|
|
|
|
68
|
return ($i, $self->{'sum'} += _totient($i)); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub ith { |
65
|
39
|
|
|
39
|
1
|
123
|
my ($self, $i) = @_; |
66
|
|
|
|
|
|
|
### TotientCumulative ith(): $i |
67
|
|
|
|
|
|
|
|
68
|
39
|
50
|
|
|
|
95
|
if (_is_infinite($i)) { |
69
|
0
|
|
|
|
|
0
|
return $i; |
70
|
|
|
|
|
|
|
} |
71
|
39
|
|
|
|
|
59
|
my $sum = 0; |
72
|
39
|
|
|
|
|
77
|
foreach my $n (1 .. $i) { |
73
|
287
|
|
|
|
|
626
|
$sum += _totient($n); |
74
|
|
|
|
|
|
|
} |
75
|
39
|
|
|
|
|
147
|
return $sum; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub pred { |
79
|
97
|
|
|
97
|
1
|
605
|
my ($self, $value) = @_; |
80
|
|
|
|
|
|
|
### TotientCumulative pred(): $value |
81
|
|
|
|
|
|
|
|
82
|
97
|
50
|
|
|
|
227
|
if (_is_infinite($value)) { |
83
|
0
|
|
|
|
|
0
|
return 0; |
84
|
|
|
|
|
|
|
} |
85
|
97
|
|
|
|
|
175
|
my $sum = 0; |
86
|
97
|
|
|
|
|
129
|
for (my $n = 0; ; $n++) { |
87
|
912
|
100
|
|
|
|
1786
|
if ($sum == $value) { |
88
|
24
|
|
|
|
|
71
|
return 1; |
89
|
|
|
|
|
|
|
} |
90
|
888
|
100
|
|
|
|
1926
|
if ($sum > $value) { |
91
|
73
|
|
|
|
|
213
|
return 0; |
92
|
|
|
|
|
|
|
} |
93
|
815
|
|
|
|
|
1740
|
$sum += _totient($n); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
__END__ |