import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
StringBuffer sb = new StringBuffer("");
String m = "";
boolean notPrime[] = sievePrime(1000 * 1000);
while ((m = br.readLine()) != null) {
int x = Integer.parseInt(m);
if (notPrime[x]) {
sb.append(x).append(" is not prime.\n");
} else {
int temp=reverse(x);
if (notPrime[temp] || temp==x) {
sb.append(x).append(" is prime.\n");
} else {
sb.append(x).append(" is emirp.\n");
}
}
}
System.out.print(sb);
}
static boolean[] sievePrime(int x) {
boolean[] notPrime = new boolean[x + 1];
notPrime[0] = true;
notPrime[1] = true;
for (int i = 2; i * i < x + 1; i++) {
if (!notPrime[i]) {
for (int j = i; i * j < x + 1; j++) {
notPrime[i * j] = true;
}
}
}
return notPrime;
}
static int reverse(int x) {
StringBuilder sb = new StringBuilder(x + "");
sb = sb.reverse();
return Integer.parseInt(sb.toString());
}
}
No comments:
Post a Comment