| 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 | package Math::NumSeq::PowerPart; | ||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use 5.004; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use vars '$VERSION','@ISA'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 23 | 1 | $VERSION = 75; | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use Math::NumSeq; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use Math::NumSeq::Base::IterateIth; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 27 | 1 | @ISA = ('Math::NumSeq::Base::IterateIth', | |||||||||||||||||||||||||||||||
| 28 | 'Math::NumSeq'); | ||||||||||||||||||||||||||||||||
| 29 | 1 | *_is_infinite = \&Math::NumSeq::_is_infinite; | |||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | use Math::NumSeq::PrimeFactorCount; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 32 | 1 | *_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 | ▶ | use constant characteristic_non_decreasing => 0; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | use constant characteristic_increasing => 0; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | use constant characteristic_integer => 1; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | use constant characteristic_smaller => 1; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | use constant values_min => 1; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | use constant i_start => 1; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 4 | ▶ | sub description { | ||||||||||||||||||||||||||||||
|
Subroutine
description: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 47 | 4 | 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 | ▶ | : sprintf('%sth',$self->{'power'})); | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
not ref $self or $self->{"power"} == 2
MC/DC100%2/2
not ref $self or $self->{"power"} == 2
not ref $self
$self->{"power"} == 2
Truth table100%3/3
not(A) or B
A= not ref $selfB= $self->{"power"} == 2
| |||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | use constant parameter_info_array => | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 55 | [ | ||||||||||||||||||||||||||||||||
| 56 | { name => 'power', | ||||||||||||||||||||||||||||||||
| 57 | type => 'integer', | ||||||||||||||||||||||||||||||||
| 58 | default => '2', | ||||||||||||||||||||||||||||||||
| 59 | minimum => 2, | ||||||||||||||||||||||||||||||||
| 60 | width => 2, | ||||||||||||||||||||||||||||||||
| 61 | # description => Math::NumSeq::__(''), | ||||||||||||||||||||||||||||||||
| 62 | }, | ||||||||||||||||||||||||||||||||
| 63 | 1 | ]; | |||||||||||||||||||||||||||||||
| 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 | 1 | = ( | |||||||||||||||||||||||||||||||
| 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 | 2 | ▶ | sub oeis_anum { | ||||||||||||||||||||||||||||||
|
Subroutine
oeis_anum: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 81 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 82 | 2 | return $oeis_anum[$self->{'power'}]; | |||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 392 | ▶ | sub ith { | ||||||||||||||||||||||||||||||
|
Subroutine
ith: called CC=7 SCAR=19.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 88 | 392 | my ($self, $i) = @_; | |||||||||||||||||||||||||||||||
| 89 | ### PowerPart ith(): $i | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 392 | $i = abs($i); | |||||||||||||||||||||||||||||||
| 92 | 392 | my $power = $self->{'power'}; | |||||||||||||||||||||||||||||||
| 93 | 392 | ▶ | if ($power < 2) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 94 | 0 | return $i; | |||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | 392 | ▶ | unless ($i >= 0) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 97 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | 392 | my ($good, @primes) = _prime_factors($i); | |||||||||||||||||||||||||||||||
| 100 | 392 | ▶ | return undef unless $good; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | 392 | my $prev = 0; | |||||||||||||||||||||||||||||||
| 103 | 392 | my $count = 0; | |||||||||||||||||||||||||||||||
| 104 | 392 | my $ret = 1; | |||||||||||||||||||||||||||||||
| 105 | 392 | foreach my $p (@primes) { | |||||||||||||||||||||||||||||||
| 106 | ### $p | ||||||||||||||||||||||||||||||||
| 107 | 737 | ▶ | if ($p == $prev) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 108 | ### same ... | ||||||||||||||||||||||||||||||||
| 109 | ### $count | ||||||||||||||||||||||||||||||||
| 110 | 217 | ▶ | if (++$count == $power) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 111 | ### incorporate ... | ||||||||||||||||||||||||||||||||
| 112 | 59 | $ret *= $p; | |||||||||||||||||||||||||||||||
| 113 | 59 | $count = 0; | |||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||
| 115 | } else { | ||||||||||||||||||||||||||||||||
| 116 | ### different ... | ||||||||||||||||||||||||||||||||
| 117 | 520 | $count = 1; | |||||||||||||||||||||||||||||||
| 118 | 520 | $prev = $p; | |||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||
| 121 | 392 | return $ret; | |||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | 28 | ▶ | sub pred { | ||||||||||||||||||||||||||||||
|
Subroutine
pred: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 125 | 28 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||
| 126 | 28 | ▶ | return ($value == int($value) && $value >= 1); | ||||||||||||||||||||||||||||||
|
Condition33%1/3
$value == int $value && $value >= 1
MC/DC0%0/2
$value == int $value && $value >= 1
$value == int $value
$value >= 1
Truth table33%1/3
A && B
A= $value == int $valueB= $value >= 1
| |||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | 1 | 1; | |||||||||||||||||||||||||||||||
| 130 | __END__ | ||||||||||||||||||||||||||||||||