Learn R Programming

pracma (version 0.7.5)

ifactor: Prime Factors

Description

Returns a vector containing the prime ifactor of n.

Usage

ifactor(n)

Arguments

n
nonnegative integer

Value

  • vector containing the prime factors of n.

Details

Computes the prime factors of n in ascending order, each one as often as its multiplicity requires, such that n == prod(ifactor(n)).

The corresponding Matlab function is called `factor', but because factors have a special meaning in R and the factor() funtion in R could not (or should not) be shadowed, the number theoretic function has been renamed here.

See Also

isprime, primes

Examples

Run this code
ifactor(1002001)       # 7  7  11  11  13  13
  ifactor(65537)         # is prime
  # Euler's calculation
  ifactor(2^32 + 1)      # 641  6700417

Run the code above in your browser using DataLab