wybstg_zd @ 2024-11-13 23:02:08
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a = sc.nextInt();
for (int i = n; i < a; i++) {
if (i % 2 == 0 ) continue; // 跳过所有偶数
if (isH(i) && isZ(i)) {
System.out.println(i);
}
}
sc.close();
}
public static boolean isH(int num) {
int original = num;
int reversed = 0;
while (num > 0) {
reversed = reversed * 10 + num % 10;
num /= 10;
}
return original == reversed;
}
public static boolean isZ(int num) {
if (num <= 1) return false;
if (num == 2 || num == 3) return true;
if (num % 2 == 0 || num % 3 == 0) return false;
for (int i = 5; i * i <= num; i += 6) {
if (num % i == 0 || num % (i + 2) == 0) return false;
}
return true;
}
}