88,最后一个超时了
查看原帖
88,最后一个超时了
823906
13813675795hzq楼主2023/2/26 09:45
#include <iostream>
#include <string>
using namespace std;

int a1(int x)
{
    for (int i = 2; i * i <= x; i++)
    {
        if (x % i == 0) return 0;
    }
    return 1;
}
int a2(string x)
{
    for (int i = 0; i <= (x.size() - 1) / 2; i++)
    {
        if (x[i] != x[x.size() - 1 - i]) return 0;
    }
    return 1;
}

int main()
{
    int b, e;
    cin >> b >> e;
    for (int i = b; i <= e; i++)
    {
        int t = i;
        string s = "";
        while (t != 0) {s += t % 10 + '0'; t /= 10;}
        if (a2(s) && a1(i)) cout << i << "\n";
        
    }
    
    return 0;
}
2023/2/26 09:45
加载中...