fork download
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class Main {
  6. public static void main(String[] args) throws IOException {
  7. int n = Integer.parseInt(br.readLine());
  8.  
  9. int[] arr = new int[1000001];
  10.  
  11. for (int i = 2; i < arr.length; i++) {
  12. arr[i] = i;
  13. }
  14.  
  15. for (int i = 2; i <= Math.sqrt(arr.length); i++) {
  16. if (arr[i] == 0) {
  17. continue;
  18. }
  19. for (int j = i * i; j < arr.length; j += i) {
  20. arr[j] = 0;
  21. }
  22. }
  23.  
  24. for (int i = n; i < arr.length; i++) {
  25. if (arr[i] != 0) {
  26. if (isPal(arr[i])) {
  27. System.out.println(arr[i]);
  28. break;
  29. }
  30. }
  31. }
  32. }
  33.  
  34. static boolean isPal(int num) {
  35. char[] temp = String.valueOf(num).toCharArray();
  36. int s = 0;
  37. int e = temp.length - 1;
  38.  
  39. while (s < e) {
  40. if (temp[s] != temp[e]) {
  41. return false;
  42. }
  43. s++;
  44. e--;
  45. }
  46.  
  47. return true;
  48. }
  49. }
  50.  
Success #stdin #stdout 0.11s 57520KB
stdin
1000000
stdout
Standard output is empty