Project Euler #3: Largest prime factor

  • + 0 comments

    Can anyone pleasee help me find the 5th Testcase issue or an error in my code? That is the only one failing:

    fun main(args: Array<String>) {
        val t = readLine()!!.trim().toInt()
    
        for (tItr in 1..t) {
            val n = readLine()!!.trim().toLong()
            getLargePrime(n)
        }
    }
    
    private fun getLargePrime(n: Long){
        /*
            large = 0
            check prime and large than small, assign
        */
        var i = 2L
        var number = n
        var large = 0L
        while (i <= number) {
            if (number % i == 0L) {
                if(large < i) large = i            
                number /= i
                i--
            }
            i++
        }
        println(large)
    }