++ed by:
Kevin Ryde
and 1 contributors

# NAME

Math::NumSeq::PrimeFactorCount -- how many prime factors

# SYNOPSIS

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

# DESCRIPTION

The sequence of how many prime factors in i, being

``    0, 1, 1, 2, 1, 2, ...``

The sequence starts from i=1 and 1 is taken to have no prime factors. Then i=2 and i=3 are themselves primes, so 1 prime factor. Then i=4 is 2*2 which is 2 prime factors.

The `multiplicity => "distinct"` option can control whether repeats of a prime factors are counted, or only distinct primes. For example with "distinct" i=4=2*2 is just 1 prime factor.

# FUNCTIONS

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

`\$seq = Math::NumSeq::PrimeFactorCount->new ()`
`\$seq = Math::NumSeq::PrimeFactorCount->new (multiplicity => \$str, prime_type => \$str)`

Create and return a new sequence object.

Option `multiplicity` is a string either

``````    "repeated"      count repeats of primes (the default)
"distinct"      count only distinct primes``````

Option `prime_type` is a string either

``````    "all"           count all primes
"odd"           count only odd primes (ie. not 2)
"4k+1"          count only primes 4k+1
"4k+3"          count only primes 4k+3
"twin"          count only twin primes
(P for which P+2 or P-2 also prime)
"SG"            count only Sophie Germain primes
(P for which 2P+1 also prime)
"safe"          count only "safe" primes
(P for which (P-1)/2 also prime)``````

"twin" counts both primes of each twin prime pair, so all of 3,5,7, 11,13, 17,19, etc.

## Random Access

`\$value = \$seq->ith(\$i)`

Return the number of prime factors in `\$i`.

This calculation requires factorizing `\$i` and in the current code after small factors a hard limit of 2**32 is enforced in the interests of not going into a near-infinite loop.

`\$bool = \$seq->pred(\$value)`

Return true if `\$value` occurs in the sequence, which means simply integer `\$value >= 0`.