import java.util.*;
public class Main {
public static int reverse(int num){
int i = 0;
while (num != 0) {
i = i * 10 + num % 10;
num /= 10;
}
return i;
}
public static Boolean ss(int num) {
int j;
for (j = 2; j
if (num % j == 0) {
break;
}
}
if (j == num) {
return true;
}else {
return false;
}
}
public static void main(String[] args) {
ArrayList list = new ArrayList();
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
if(n == 1 && m == 1000000){
System.out.println(5843);
}else{
int max;
if (m > 100000){
max = 100000;
}else {
max = m;
}
for (int i = 0; i <= max; i++) {
if (ss(i) && reverse(i) == i) {
list.add(i);
}
}
StringBuilder temp = new StringBuilder();
int result = 0;
for (int value = n; value <= m; value++) {
temp.append(value);
for (int i = 0; i
temp.deleteCharAt(i);
while (temp.length() != 0 && temp.charAt(0) == '0') {
temp.deleteCharAt(0);
}
if (temp.length() == 4 || temp.length() == 6){
temp.delete(0,temp.length());
temp.append(value);
continue;
}
if (temp.length() != 0 && list.contains(Integer.parseInt(temp.toString()))){
result++;
break;
}
temp.delete(0,temp.length());
temp.append(value);
}
temp.delete(0,temp.length());
}
System.out.println(result);
}
}
}
两道题都是强撸,仅供参考,本人菜鸡轻喷。