primeFactorize | R Documentation |

Implementation of Pollard's rho algorithm for generating the prime factorization. The algorithm is based on the "factorize.c" source file from the gmp library found here https://gmplib.org.

```
primeFactorize(v, namedList = FALSE, nThreads = NULL)
```

`v` |
Vector of integers or numeric values. Non-integral values will be cured to whole numbers. |

`namedList` |
Logical flag. If |

`nThreads` |
Specific number of threads to be used. The default is |

As noted in the Description section above, this algorithm is based on the "factorize.c" source code from the gmp library. Much of the code in RcppAlgos::primeFactorize is a straightforward translation from multiple precision C data types to standard C++ data types. A crucial part of the algorithm's efficiency is based on quickly determining primality, which is easily computed with gmp. However, with standard C++, this is quite challenging. Much of the research for RcppAlgos::primeFactorize was focused on developing an algorithm that could accurately and efficiently compute primality.

For more details, see the documentation for `isPrimeRcpp`

.

Returns an unnamed vector if

`length(v) == 1`

regardless of the value of`namedList`

. If`v < 2^{31}`

, the class of the returned vector will be integer, otherwise the class will be numeric.If

`length(v) > 1`

, a named/unnamed list of vectors will be returned. If`max(bound1, bound2)`

`< 2^{31}`

, the class of each vector will be integer, otherwise the class will be numeric.

The maximum value for each element in `v`

is `2^{53} - 1`

.

Joseph Wood

`primeFactorizeSieve`

, `factorize`

```
## Get the prime factorization of a single number
primeFactorize(10^8)
## Or get the prime factorization of many numbers
set.seed(29)
myVec <- sample(-1000000:1000000, 1000)
system.time(pFacs <- primeFactorize(myVec))
## Return named list
pFacsWithNames <- primeFactorize(myVec, namedList = TRUE)
## Using nThreads
system.time(primeFactorize(myVec, nThreads = 2))
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.