The prime_factors function is used to calculate the prime factors of a positive integer greater than 1.

prime_factors(x, unique = TRUE)

Arguments

x

The number that you want the prime factors of.

unique

Logical. Should the function return all prime factors (where prod(prime_factors(x)) == x) or just the unique prime factors? Defaults to TRUE.

Value

A numeric vector either with the repeated prime factorization of the input or just the unique prime factors of the input.

Note

Returns NULL for a value of 1, and generates an error for values less than 1.

Examples

prime_factors(100, unique = FALSE)
#> [1] 2 2 5 5
prime_factors(100)
#> [1] 2 5