import java.io.*;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.IntStream;
public class Main {
private static final int <i>MAX </i>= 1_000_001;
private static boolean[] <i>isPrime</i>;
static {
<i>sieveOfEratosthenes</i>();
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.<i>in</i>));
int n = Integer.<i>parseInt</i>(br.readLine());
Predicate<Integer> isPalindrome = i -> {
String str = Integer.<i>toString</i>(i);
int len = str.length();
int left = 0;
int right = len - 1;
while (left < right) {
if (str.charAt(left++) != str.charAt(right--)) {
return false;
}
}
return true;
};
IntStream.<i>range</i>(n, <i>MAX</i>)
.filter(i -> <i>isPrime</i>[i] && isPalindrome.test(i))
.findFirst()
.ifPresent(System.<i>out</i>::println);
} // end of main
private static void sieveOfEratosthenes() {
<i>isPrime </i>= new boolean[<i>MAX</i>];
Arrays.<i>fill</i>(<i>isPrime</i>, true);
<i>isPrime</i>[0] = <i>isPrime</i>[1] = false;
double endCondition = Math.<i>sqrt</i>(<i>MAX</i>);
for (int i = 2; i < endCondition; i++) {
if (<i>isPrime</i>[i]) {
for (int j = i * i; j < <i>MAX</i>; j += i) {
<i>isPrime</i>[j] = false;
}
}
}
} // end of sieveOfEratosthenes
} // end of class
cyberkdy 2년 전
import java.io.*; import java.util.*; import java.util.function.Predicate; import java.util.stream.IntStream; public class Main { private static final int <i>MAX </i>= 1_000_001; private static boolean[] <i>isPrime</i>; static { <i>sieveOfEratosthenes</i>(); } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.<i>in</i>)); int n = Integer.<i>parseInt</i>(br.readLine()); Predicate<Integer> isPalindrome = i -> { String str = Integer.<i>toString</i>(i); int len = str.length(); int left = 0; int right = len - 1; while (left < right) { if (str.charAt(left++) != str.charAt(right--)) { return false; } } return true; }; IntStream.<i>range</i>(n, <i>MAX</i>) .filter(i -> <i>isPrime</i>[i] && isPalindrome.test(i)) .findFirst() .ifPresent(System.<i>out</i>::println); } // end of main private static void sieveOfEratosthenes() { <i>isPrime </i>= new boolean[<i>MAX</i>]; Arrays.<i>fill</i>(<i>isPrime</i>, true); <i>isPrime</i>[0] = <i>isPrime</i>[1] = false; double endCondition = Math.<i>sqrt</i>(<i>MAX</i>); for (int i = 2; i < endCondition; i++) { if (<i>isPrime</i>[i]) { for (int j = i * i; j < <i>MAX</i>; j += i) { <i>isPrime</i>[j] = false; } } } } // end of sieveOfEratosthenes } // end of class