class PrimeFactorCalculator {
    companion object {
        fun primeFactors(num: Int): List<Int> = primeFactors(num.toLong()).map { it.toInt() }

        fun primeFactors(num: Long): List<Long> {
            var tempNum = num
            val returnList = mutableListOf<Long>()
            while (tempNum != 1L){
                val smallestPrimeFactor = tempNum.smallestPrimeFactor()
                returnList.add(smallestPrimeFactor)
                tempNum /= smallestPrimeFactor
                if (smallestPrimeFactor == 1L){
                    tempNum = 1L
                }
            }
            return returnList
        }
    }
}

fun Int.isPrime(): Boolean = this.toLong().isPrime()

fun Long.isPrime(): Boolean {
    for (i in 2..Math.sqrt(this.toDouble()).toLong()) {
        if (this.rem(i) == 0L) return false
    }
    return true
}

fun Int.smallestPrimeFactor(): Int = this.toLong().smallestPrimeFactor().toInt()

fun Long.smallestPrimeFactor(): Long{
    for (i in 2..this){
        if (this.rem(i) == 0L){
            return i
        }
    }
    return 1
}