Prime Factors Algorithm
In abstract algebra, objects that behave in a generalized manner like prime numbers include prime components and prime ideals. A prime number (or a prime) is a natural number greater than 1 that is not a merchandise of two smaller natural numbers. method that are restricted to specific number forms include Pépin's test for Fermat numbers (1877), Proth's theorem (c. 1878), the Lucas – Lehmer primality test (originated 1856), and the generalized Lucas primality test.
package Mathematics
object PrimeFactors {
/**
* Method returns list of prime factors of number n
*
* @param num
* @return
*/
def primeFactors(number: Long): List[Long] = {
val exists = (2L to math.sqrt(number).toLong).find(number % _ == 0)
exists match {
case None => List(number)
case Some(factor) => factor :: primeFactors(number/factor)
}
}
}