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
|
|
|
|
|
|
|
package Math::NumSeq::PowerPart; |
19
|
1
|
|
|
1
|
|
1438
|
use 5.004; |
|
1
|
|
|
|
|
4
|
|
20
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
6
|
use vars '$VERSION','@ISA'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
89
|
|
23
|
|
|
|
|
|
|
$VERSION = 72; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
7
|
use Math::NumSeq; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
26
|
1
|
|
|
1
|
|
5
|
use Math::NumSeq::Base::IterateIth; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
58
|
|
27
|
|
|
|
|
|
|
@ISA = ('Math::NumSeq::Base::IterateIth', |
28
|
|
|
|
|
|
|
'Math::NumSeq'); |
29
|
|
|
|
|
|
|
*_is_infinite = \&Math::NumSeq::_is_infinite; |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
6
|
use Math::NumSeq::PrimeFactorCount; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
47
|
|
32
|
|
|
|
|
|
|
*_prime_factors = \&Math::NumSeq::PrimeFactorCount::_prime_factors; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# uncomment this to run the ### lines |
35
|
|
|
|
|
|
|
#use Smart::Comments; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# use constant name => Math::NumSeq::__('Powered Part'); |
39
|
1
|
|
|
1
|
|
6
|
use constant characteristic_non_decreasing => 0; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
79
|
|
40
|
1
|
|
|
1
|
|
6
|
use constant characteristic_increasing => 0; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
57
|
|
41
|
1
|
|
|
1
|
|
6
|
use constant characteristic_integer => 1; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
63
|
|
42
|
1
|
|
|
1
|
|
7
|
use constant characteristic_smaller => 1; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
43
|
1
|
|
|
1
|
|
6
|
use constant values_min => 1; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
59
|
|
44
|
1
|
|
|
1
|
|
6
|
use constant i_start => 1; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
167
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub description { |
47
|
4
|
|
|
4
|
1
|
15
|
my ($self) = @_; |
48
|
|
|
|
|
|
|
return sprintf(Math::NumSeq::__('Largest %s dividing i.'), |
49
|
|
|
|
|
|
|
! ref $self || $self->{'power'} == 2 ? 'square' |
50
|
|
|
|
|
|
|
: $self->{'power'} == 3 ? 'cube' |
51
|
4
|
50
|
100
|
|
|
8
|
: sprintf('%sth',$self->{'power'})); |
|
|
100
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
369
|
use constant parameter_info_array => |
55
|
|
|
|
|
|
|
[ |
56
|
|
|
|
|
|
|
{ name => 'power', |
57
|
|
|
|
|
|
|
type => 'integer', |
58
|
|
|
|
|
|
|
default => '2', |
59
|
|
|
|
|
|
|
minimum => 2, |
60
|
|
|
|
|
|
|
width => 2, |
61
|
|
|
|
|
|
|
# description => Math::NumSeq::__(''), |
62
|
|
|
|
|
|
|
}, |
63
|
1
|
|
|
1
|
|
6
|
]; |
|
1
|
|
|
|
|
2
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
66
|
|
|
|
|
|
|
# cf A008833 - largest square dividing n |
67
|
|
|
|
|
|
|
# A008834 - largest cube dividing n |
68
|
|
|
|
|
|
|
# A008835 - largest 4th power dividing n |
69
|
|
|
|
|
|
|
# |
70
|
|
|
|
|
|
|
my @oeis_anum |
71
|
|
|
|
|
|
|
= ( |
72
|
|
|
|
|
|
|
# OEIS-Catalogue array begin |
73
|
|
|
|
|
|
|
undef, |
74
|
|
|
|
|
|
|
undef, |
75
|
|
|
|
|
|
|
'A000188', # # 2 sqrt of largest square dividing n |
76
|
|
|
|
|
|
|
'A053150', # power=3 # 3 cbrt of largest cube dividing n |
77
|
|
|
|
|
|
|
'A053164', # power=4 # 4th root of largest 4th power dividing n |
78
|
|
|
|
|
|
|
# OEIS-Catalogue array end |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
sub oeis_anum { |
81
|
2
|
|
|
2
|
1
|
8
|
my ($self) = @_; |
82
|
2
|
|
|
|
|
6
|
return $oeis_anum[$self->{'power'}]; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub ith { |
88
|
392
|
|
|
392
|
1
|
350
|
my ($self, $i) = @_; |
89
|
|
|
|
|
|
|
### PowerPart ith(): $i |
90
|
|
|
|
|
|
|
|
91
|
392
|
|
|
|
|
257
|
$i = abs($i); |
92
|
392
|
|
|
|
|
303
|
my $power = $self->{'power'}; |
93
|
392
|
50
|
|
|
|
518
|
if ($power < 2) { |
94
|
0
|
|
|
|
|
0
|
return $i; |
95
|
|
|
|
|
|
|
} |
96
|
392
|
50
|
|
|
|
430
|
unless ($i >= 0) { |
97
|
0
|
|
|
|
|
0
|
return undef; |
98
|
|
|
|
|
|
|
} |
99
|
392
|
|
|
|
|
506
|
my ($good, @primes) = _prime_factors($i); |
100
|
392
|
50
|
|
|
|
489
|
return undef unless $good; |
101
|
|
|
|
|
|
|
|
102
|
392
|
|
|
|
|
240
|
my $prev = 0; |
103
|
392
|
|
|
|
|
229
|
my $count = 0; |
104
|
392
|
|
|
|
|
221
|
my $ret = 1; |
105
|
392
|
|
|
|
|
361
|
foreach my $p (@primes) { |
106
|
|
|
|
|
|
|
### $p |
107
|
737
|
100
|
|
|
|
711
|
if ($p == $prev) { |
108
|
|
|
|
|
|
|
### same ... |
109
|
|
|
|
|
|
|
### $count |
110
|
217
|
100
|
|
|
|
278
|
if (++$count == $power) { |
111
|
|
|
|
|
|
|
### incorporate ... |
112
|
59
|
|
|
|
|
42
|
$ret *= $p; |
113
|
59
|
|
|
|
|
53
|
$count = 0; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} else { |
116
|
|
|
|
|
|
|
### different ... |
117
|
520
|
|
|
|
|
324
|
$count = 1; |
118
|
520
|
|
|
|
|
431
|
$prev = $p; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
392
|
|
|
|
|
665
|
return $ret; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub pred { |
125
|
28
|
|
|
28
|
1
|
73
|
my ($self, $value) = @_; |
126
|
28
|
|
33
|
|
|
64
|
return ($value == int($value) && $value >= 1); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
__END__ |