解题思路:
import java.util.Scanner; public class C1250 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int a = sc.nextInt(), b = sc.nextInt(); for(int n = a; n <= b; n++){ if(F(n)) System.out.println(n); } } sc.close(); } private static boolean F(int n){ //1. 判断是否为素数 for(int i = 2; i * i <= n; i++){ if(n % i == 0) return false; } //2. 判断是否为回文数 String str = String.valueOf(n); int len = str.length(); for(int i = 0; i <= len/2; i++){ if(str.charAt(i) != str.charAt(len-1-i)) return false; } //默认返回true return true; } }
注意事项:
参考代码:
0.0分
0 人评分