1Math::Factor::XS(3)   User Contributed Perl Documentation  Math::Factor::XS(3)
2
3
4

NAME

6       Math::Factor::XS - Factorize numbers and calculate matching
7       multiplications
8

SYNOPSIS

10        use Math::Factor::XS ':all';
11        # or
12        use Math::Factor::XS qw(factors prime_factors matches);
13
14        $number = 30107;
15
16        @factors = factors($number);
17        @primes = prime_factors($number);
18        @matches = matches($number, \@factors);
19
20        print "$factors[1]\n";
21        print "$number == $matches[0][0] * $matches[0][1]\n";
22

DESCRIPTION

24       "Math::Factor::XS" factorizes numbers by applying trial divisions.
25

FUNCTIONS

27   factors
28       Find all factors (ie. divisors) of a number.
29
30        @factors = factors($number);
31
32       The number is factorized and its factors are returned as a list.  For
33       example,
34
35        @factors = factors(30);
36        #  @factors = (2, 3, 5, 6, 10, 15);
37
38   prime_factors
39       Find prime factors of a number.
40
41        @factors = prime_factors($number);
42
43       The number is factorized and its prime factors are returned as a list.
44       Multiplying the list together gives $number.  For example,
45
46        @primes = prime_factors(90);
47        #  @primes = (2, 3, 3, 5);
48
49   count_prime_factors
50       Return the count of prime factors of a number.  This is the number of
51       values returned by "prime_factors()".
52
53        my $count = count_prime_factors($number);
54
55   matches
56       Calculates matching multiplications.
57
58        @matches = matches($number, \@factors, { skip_multiples => [0|1] });
59
60       The factors will be multiplied against each other and all combinations
61       that equal the number itself will be returned as a two-dimensional
62       list.  The matches are accessible through the indexes; for example, the
63       first two numbers that matched the number may be accessed by
64       $matches[0][0] and $matches[0][1], the second pair by $matches[1][0]
65       and $matches[1][1], and so on.
66
67       The hashref provided at the end is optional. If "skip_multiples" is set
68       to a true value, then matching multiplications that contain
69       multiplicated small factors will be discarded. Example:
70
71        11 * 2737 == 30107 # accepted
72        77 * 391  == 30107 # discarded
73
74       Direct use of $Math::Factor::XS::Skip_multiple does no longer have an
75       effect as it has been superseded by "skip_multiples".
76

EXPORT

78   Functions
79       "factors()", "matches()" and "prime_factors()" are exportable.
80
81   Tags
82       ":all - *()"
83

AUTHOR

85       Steven Schubiger <schubiger@cpan.org>
86

LICENSE

88       This program is free software; you may redistribute it and/or modify it
89       under the same terms as Perl itself.
90
91       See <http://dev.perl.org/licenses/>
92
93
94
95perl v5.36.0                      2022-07-22               Math::Factor::XS(3)
Impressum