最后三个测试点显示超时,求修改
查看原帖
最后三个测试点显示超时,求修改
481792
nbge楼主2021/3/8 17:04
#include<iostream>

using namespace std;

int isPrime(int n);
int isPals(int n);

int main()
{
	int a, b;
	cin >> a >> b;
	for (int i = a; i <= b; i++)
	{
		if (isPrime(i) == 1 )
		    if(isPals(i) == 1)
			    cout << i << endl;
	}
	return 0;
}

int isPrime(int n)
{
	int x = n, y = 0;
	while (x > 0)
	{
		y = y * 10 + x % 10;
		x /= 10;
	}
	if (n == y)
		return 1;
	return 0;
}

int isPals(int n)
{
	for (int i = 2; i < n/2+1; i++)
		if (n % i == 0)
			return 0;
	return 1;
}
2021/3/8 17:04
加载中...