import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int m = scanner.nextInt(); int n = scanner.nextInt(); int count = 0; for (int i = m; i <= n; i++) { if (util(i)){ System.out.printf("%6d",i); if (++count % 5 == 0) System.out.println(); } } } public static boolean util(int a){ for (int i = 2; i <= Math.sqrt(a); i++) { if (a % i == 0){ return false; } } String temp = a+""; int i = 0, j = temp.length()-1; while (i < j){ if (temp.charAt(i) != temp.charAt(j))return false; i++; j--; } return true; } } |
Double click to view unformatted code.