-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ03008.java
More file actions
37 lines (35 loc) · 1.01 KB
/
J03008.java
File metadata and controls
37 lines (35 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package CODE_PTIT;
import java.util.*;
public class J03008 {
public static int ThuanNghich(String s){
int l = 0, r = s.length()-1;
while(l < r){
if(s.charAt(l) != s.charAt(r)) return 0;
l++; r--;
}
return 1;
}
public static int Prime(String s){
for(int i = 0; i < s.length();i++){
if((s.charAt(i) - '0') != 2 &&
(s.charAt(i) - '0') != 3 &&
(s.charAt(i) - '0') != 5 &&
(s.charAt(i) - '0') != 7) return 0;
}
return 1;
}
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
int t;
t = Integer.parseInt(inp.nextLine());
while(t-- > 0){
String s = inp.nextLine();
if(ThuanNghich(s) == 1 && Prime(s) == 1){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
}