package pl.polgrabia.demos.crackingcodeinterview.t17x9

fun main() {
    print("Max size: ")
    val maxSize = readln().toInt()
    print("K number: ")
    val kNumber = readln().toInt()

    val arr = Array(maxSize + 1, { false })
    for (i in 3 until maxSize + 1 - kNumber step 3) {
        arr[i] = true
    }

    for (i in 5 until maxSize + 1 - kNumber step 5) {
        arr[i] = true
    }

    for (i in 7 until maxSize + 1 - kNumber step 7) {
        arr[i] = true
    }

    var counter = 0
    var kNumberValue = -1
    for (i in 2 until maxSize + 1) {
        if (arr[i] && ++counter >= kNumber) {
            kNumberValue = i
            break
        }
    }

    println("Found k number $kNumber with value $kNumberValue")

}