求助,66分,WA TLE TLE
查看原帖
求助,66分,WA TLE TLE
1287110
145a楼主2024/2/29 13:06
#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;

}
2024/2/29 13:06
加载中...