fun main(args: Array){ val k = readLine()!!.toInt() val n = readLine()!!.toInt() val primeList = getPrimeList(n).filter { it >= k } val convList = primeList.map { getConv(it) } var fromIdx = 0 var maxLength = 0 var maxFromIdx = 0 val dic = mutableMapOf() for(i in convList.indices) { if(dic.containsKey(convList[i])) { for(j in fromIdx..i) { dic.remove(convList[j]) if(convList[j] == convList[i]) { fromIdx = j+1 break } } } dic[convList[i]] = true val len = i - fromIdx + 1 if(len >= maxLength) { maxLength = len maxFromIdx = fromIdx } } println(primeList[maxFromIdx]) } fun getConv(inNum: Int):Int { if(inNum < 10) { return inNum } val outNum = getConv((inNum/10) + (inNum%10)) return outNum } fun getPrimeList(maxNum:Int):List { val flags = arrayOfNulls(maxNum+1) val list = mutableListOf() for (i in 2..maxNum) { if(flags[i] != null && flags[i]!!) { continue } val maxIndex = maxNum/i for(j in 1..maxIndex) { flags[i*j] = true } list.add(i) } return list.toList() }