解题思路:
注意事项:
参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); for(int i = 2;i <= n;i++){ if(isPrime(i) && isPrime(i+2)){ System.out.println(i+" "+(i+2)); } } } public static boolean isPrime(int n){ if(n == 1) return false; for(int i = 2; i * i <= n; ++i){ if(n % i == 0) return false; } return true; } }
0.0分
0 人评分