7 10000000 那个测试点WA TLE
#include<iostream>
#include<bitset>
#include<algorithm>
#include<vector>
using namespace std;
auto getPrimeList()
{
const unsigned int maxNum = 10000000;
bitset<maxNum> compositeTagList;
vector<unsigned int> primeList = {};
for (unsigned int i = 2; i < maxNum; i += 1)
{
if (compositeTagList[i] == false)
{
for (unsigned long int j = i * i; j < maxNum; j += i)
{
if (compositeTagList[j] == false)
compositeTagList[j] = true;
}
primeList.push_back(i);
}
}
return primeList;
}
auto primeList = getPrimeList();
auto isPrime(unsigned int x)
{
return binary_search(primeList.begin(), primeList.end(), x);
}
auto isPalindrome(unsigned int x)
{
vector<unsigned short int> digits = {};
while(x > 0)
{
digits.push_back(x % 10);
x /= 10;
}
for(unsigned short int i = 0; i < digits.size() / 2; i += 1)
{
if(digits[i] != digits[digits.size() - i - 1]) return false;
}
return true;
}
int main()
{
unsigned int a, b;
cin >> a >> b;
for (unsigned int x = a; x < b; x += 1) {
if(isPrime(x) && isPalindrome(x))
{
cout << x << endl;
}
}
return 0;
}