题解 | #查找组成一个偶数最接近的两个素数#
查找组成一个偶数最接近的两个素数
https://www.nowcoder.com/practice/f8538f9ae3f1484fb137789dec6eedb9
import java.util.Scanner fun main(args: Array<String>) { val read = Scanner(System.`in`) val res = read.nextLine().toInt() val list = mutableSetOf(2) for (i in 2..res) { var add = true for (j in 2..Math.sqrt(i.toDouble()).toInt()) { if (i % j == 0) { add = false break } } if (add) list.add(i) } var first = 2 for (it in list) { if (it > res / 2) break if (list.contains(res - it)) { first = it } } println("$first\n${res - first}") }