Steven Schubiger (stsc)

NAME

Math::Factor - Factorise numbers and calculate matching multiplications

SYNOPSIS

 use Math::Factor ':all';

 $number = 30107;

 @factors = factors($number);
 @matches = matches($number, @factors);

 print "$factors[1]\n";
 print "$number == $matches[0][0] * $matches[0][1]\n";

DESCRIPTION

Math::Factor factorises numbers by applying trial divison.

FUNCTIONS

factors

Factorises numbers.

 @factors = factors($number);

$number will be entirely factorised and its factors will be saved within the array @factors.

matches

Evaluates matching multiplications.

 @matches = matches($number, @factors);

The factors within @factors will be multplicated against each other and results that equal the number itself, will be saved to the two-multidimensional array @matches. The matches are accessible through the indexes, for example, the first two numbers that matched the number, may be accessed by $matches[0][0] and $matches[0][1], the second ones by $matches[1][0] and $matches[1][1], and so on.

If $Math::Factor::Skip_multiple is set to a true value, matching multiplications that contain multiplicated (small) factors will be dropped.

Example:

 # accepted 
 30107 == 11 * 2737  

 # dropped
 30107 == 77 * 391

EXPORT

factors(), matches() are exportable.

TAGS

:all - *()