| 1 | # Copyright 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::MoranNumbers; | ||||||||||||||||||||||||||||
| 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 | 1 | ▶ | use Math::Prime::XS 0.23 'is_prime'; # version 0.23 fix for 1928099 | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use vars '$VERSION', '@ISA'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 1 | $VERSION = 75; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use Math::NumSeq; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use Math::NumSeq::Base::IteratePred; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 1 | @ISA = ('Math::NumSeq::Base::IteratePred', | |||||||||||||||||||||||||||
| 29 | 'Math::NumSeq'); | ||||||||||||||||||||||||||||
| 30 | 1 | *_is_infinite = \&Math::NumSeq::_is_infinite; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # uncomment this to run the ### lines | ||||||||||||||||||||||||||||
| 33 | #use Devel::Comments; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 1 | ▶ | use constant name => Math::NumSeq::__('Moran Numbers'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | use constant description => Math::NumSeq::__('Moran numbers, divisible by the sum of their digits and that division resulting in a prime.'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 1 | ▶ | use constant i_start => 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | use Math::NumSeq::Base::Digits | ||||||||||||||||||||||||||||
| 40 | 1 | ▶ | 'parameter_info_array'; # radix parameter | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 4 | ▶ | sub values_min { | ||||||||||||||||||||||||||
|
Subroutine
values_min: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||
| 44 | 4 | ▶ | if (! $self->{'values_min'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 1 | for (my $value = $self->{'radix'}; ; $value++) { | |||||||||||||||||||||||||||
| 46 | 9 | ▶ | if ($self->pred($value)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 1 | $self->{'values_min'} = $value; | |||||||||||||||||||||||||||
| 48 | 1 | last; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | 4 | return $self->{'values_min'}; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 56 | # cf A007953 digit sum (in Math::NumSeq::DigitSum) | ||||||||||||||||||||||||||||
| 57 | # A085775 both n/digitsum(n) and (n+1)/digitsum(n+1) prime | ||||||||||||||||||||||||||||
| 58 | # A108780 n/digitsum(n) is a golden semiprime | ||||||||||||||||||||||||||||
| 59 | # A130338 primes not occurring as n/digitsum(n) | ||||||||||||||||||||||||||||
| 60 | # A003635 inconsummate, quotients not occurring as n/digitsum(n) | ||||||||||||||||||||||||||||
| 61 | # | ||||||||||||||||||||||||||||
| 62 | 1 | my @oeis_anum; | |||||||||||||||||||||||||||
| 63 | 1 | $oeis_anum[10] = 'A001101'; # OFFSET=1 | |||||||||||||||||||||||||||
| 64 | # OEIS-Catalogue: A001101 | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | ▶ | sub oeis_anum { | ||||||||||||||||||||||||||
|
Subroutine
oeis_anum: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 68 | 1 | return $oeis_anum[$self->{'radix'}]; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 578 | ▶ | sub pred { | ||||||||||||||||||||||||||
|
Subroutine
pred: called CC=7 SCAR=19.8
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 578 | my ($self, $value) = @_; | |||||||||||||||||||||||||||
| 75 | ### MoranNumbers pred(): $value | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 578 | ▶ | if ($value <= 0 || $value != int($value)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$value <= 0 or $value != int $value
MC/DC50%1/2
$value <= 0 or $value != int $value
$value <= 0
$value != int $value
Truth table66%2/3
A or B
A= $value <= 0B= $value != int $value
| |||||||||||||||||||||||||||||
| 78 | 138 | return 0; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 440 | ▶ | if (_is_infinite($value)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | return undef; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 440 | my $radix = $self->{'radix'}; | |||||||||||||||||||||||||||
| 85 | 440 | my $sum = 0; | |||||||||||||||||||||||||||
| 86 | 440 | my $v = $value; | |||||||||||||||||||||||||||
| 87 | 440 | ▶ | while ($v) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 1058 | $sum += ($v % $radix); | |||||||||||||||||||||||||||
| 89 | 1058 | $v = int($v/$radix); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 440 | ▶ | if ($value % $sum) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 303 | return 0; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | 137 | $value /= $sum; | |||||||||||||||||||||||||||
| 95 | 137 | ▶ | if ($value > 0xFFFF_FFFF) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | return undef; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 137 | return is_prime($value); | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 1 | 1; | |||||||||||||||||||||||||||
| 102 | __END__ | ||||||||||||||||||||||||||||