glory9527 @ 2024-01-28 21:22:43
import java.util.Scanner;
import java.util.Arrays;
public class Main{
public static void getPrimeArr(int arr[]) {
for(int i=0;i<arr.length;i++) {
boolean pd=true;
if(arr[i]%2==0)
continue;
for(int j=2;j<=Math.sqrt(arr[i]);j++)
if(arr[i]%j==0) {
pd=false;
break;
}
if(pd)
System.out.println(arr[i]);
}
}
public static int [] getHuiWenArr(int a,int b) {
int brr[]=new int [b-a+1];
int n=0;
for(int i=a;i<=b;i++) {
int temp=i,ans=0;
while (temp!=0) {
ans=ans*10+temp%10;
temp/=10;
}
if(i==ans) {
brr[n]=i;
n++;
}
}
int count=0;
for(int i=0;i<brr.length;i++){
count++;
if(brr[i]==0)
break;
}
int crr[]=Arrays.copyOf(brr, count-1);
return crr;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s=sc.nextLine();
String [] strArr=s.split(" ");
int arr[]=new int [2];
for(int i=0;i<2;i++)
arr[i]=Integer.parseInt(strArr[i]);
getPrimeArr(getHuiWenArr(arr[0],arr[1]));
}
}
by aikou @ 2024-01-30 16:19:14
题目下面给了提示,直接生成回文数然后判断是否是素数,你区间每一个数都判断是不是回文数肯定会超时的。