# NAME

Math::NumSeq::AlmostPrimes -- semiprimes and other fixed number of prime factors

# SYNOPSIS

`````` use Math::NumSeq::AlmostPrimes;
my \$seq = Math::NumSeq::AlmostPrimes->new (factor_count => 2);
my (\$i, \$value) = \$seq->next;``````

# DESCRIPTION

This sequence is various "almost prime" numbers. These are numbers with a given number of prime factors. The default is 2 prime factors, which are the semi-primes. For example 15 because 15=3*5.

``````    4, 6, 9, 10, 14, 15, 21, 22, 25, 26, 33, 34, 35, ...
# starting i=1``````

## Factor Count

`factor_count => \$c` controls how many prime factors are to be used. 1 would be the primes themselves (the same as Math::NumSeq::Primes). Or for example factor count 4 is as follows. 60 is present because 60=2*2*3*5 has precisely 4 prime factors.

``````    # factor_count => 4
16, 24, 36, 40, 54, 60, ...``````

The first number in the sequence is 2^factor_count, being prime factor 2 repeated factor_count many times.

## Multiplicity

`multiplicity => 'distinct'` asks for products of distinct primes. For the default factor count 2 this means exclude squares like 4=2*2, which leaves

``````    # multiplicity => 'distinct'
6, 10, 14, 15, 21, ...``````

For other factor counts, multiplicity "distinct" eliminates any numbers with repeated factors, leaving only square-free numbers. For example factor count 4 becomes

``````    # factor_count => 4, multiplicity => 'distinct'
210, 330, 390, 462, 510, 546, ...``````

For multiplicity "distinct" the first value in the sequence is a primorial (see Math::NumSeq::Primorials), being the first `factor_count` many primes multiplied together. For example 210 above is primorial 2*3*5*7.

# FUNCTIONS

See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.

`\$seq = Math::NumSeq::AlmostPrimes->new ()`
`\$seq = Math::NumSeq::AlmostPrimes->new (factor_count => \$integer, multiplicity => \$str)`

Create and return a new sequence object. `multiplicity` can be

``````    "repeated"  repeated primes allowed (the default)
"distinct"  all primes must be distinct``````
`\$bool = \$seq->pred(\$value)`

Return true if `\$value` is an almost-prime, ie. it has exactly `factor_count` many prime factors, and if `distinct` is true then all those factors different.

This check requires factorizing `\$value` and in the current code a hard limit of 2**32 is placed on values to be checked, in the interests of not going into a near-infinite loop.

Math::NumSeq::Primorials