factors
returns all the prime factors of a given number.
factors(n, iter = 10, output = "print")# S3 method for default
factors(n, iter = 10, output = "print")
# S3 method for numeric
factors(n, iter = 10, output = "print")
# S3 method for vli
factors(n, iter = 10, output = "print")
list of objects of class vli or the result displayed on the screen, depending on the output
argument
integer to be factorized; vli class object or 32 bits integer
number of iterations for testing if the given number is prime; numeric
chosen way for objects being returned: 'list'
to return the result as a list of vli objects or 'print'
(by default) to simply display the result on the screen; character
Javier Leiva Cuadrado
The implemented algorithm is based in a Monte Carlo method for integer factorization called Pollard's Rho Algorithm.
It determines if the given number is prime or composite by usign the Miller-Rabin Probabilistic Primality Test. If it is prime, it returns the number itself. If it is composite, it calls iteratively the divisor
function until all the prime factors of the given number are found.
It is a Monte Carlo method, therefore it is not deterministic. The number of iterations is configurable, to set the desired accuracy. A too low number of iterations could cause an infinite loop because of being looking for a divisor of a prime number.
x <- as.vli("584843")
factors(x, iter = 100)
Run the code above in your browser using DataLab