Project Euler #1: Multiples of 3 and 5

  • + 0 comments

    I cannot pass 2 of the tests with this Kotlin code, anybody has any idea?

    fun main(args: Array<String>) {
        val t = readLine()!!.trim().toInt()
    
        for (tItr in 1..t) {
            val n = readLine()!!.trim().toInt()
            println("${sumn(n,3)+sumn(n,5)-sumn(n,15)}")
            
        }
        
    }
    
    fun sumn(n:Int,d:Int):Int{
        val l = (n-1)/d
        return d*l*(l+1)/2
    }