大佬们,help me!编译对了,却超时了。
查看原帖
大佬们,help me!编译对了,却超时了。
1030197
nuoxi6868楼主2023/9/19 22:53
#include<bits/stdc++.h>
using namespace std;
int n=1000;
int prime(int n){
	if(n==1) return 0;
	for(int i=2;i*i<=n;i++){
		if(n%i==0){
			return 0;
		}
	}
	return 1;
}

int main(){
	int a,b,len2=0;
	cin>>a>>b;
	for(int i=a;i<=b;i++){
		if(prime(i)==1){
			int j=i;len2=0;
			while(j>=1){
				len2=(len2*10)+(j%10);
				j/=10;
			}
			if(len2==i){
				cout<<i<<endl;
			}
		}
	}
	return 0;
}
2023/9/19 22:53
加载中...