88分,最后一个超时了,还能怎么缩时间,大佬教教
查看原帖
88分,最后一个超时了,还能怎么缩时间,大佬教教
798884
hellowcworld楼主2022/12/10 17:59
//两个函数,素数判定与回文数判定
#include<iostream>
#include<cmath>
#include<cstring>
bool book[100000000];
bool palin(int n);
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	memset(book,true,sizeof(book));
	book[0]=book[1]=false;
	for(int i=2;i<=sqrt(b);i++)//列出所有质数(埃及筛法),所有质数的倍数不可能是质数 
	{
		if(book[i])
		for(int j=2;j<=b/i;j++)
		{
			book[i*j]=false;
		}
	}
	for(int index=a;index<=b;index++)
	if(book[index]==false) continue;
	else if(index==9989900) break;
	else if(palin(index)) cout<<index<<endl;
	return 0;
}
bool palin(int n)//判断回文数,及数字反转后与原数字相等 
{
	int sum=0;
	int k=n;
	while(n!=0)
	{
		sum=sum*10+n%10;
		n/=10;
	}
	if(sum==k) return true;
	else return false;
}

 
 
 
 
 
 
2022/12/10 17:59
加载中...