求助
查看原帖
求助
1381435
uwuuk楼主2024/7/23 10:06
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
void RealJudge(int t,int loc,int& judge1) {
    int temp = t;
    int judge = 0;
    string s;
    s = to_string(t);
    reverse(s.begin(),s.end());
    t = stoi(s);
    for (int j = 2; j < t; j++) {
        if (t % j == 0) {
            judge = 1;
            break;
        }
    }
    if (judge == 0) {
        if (loc == 0) {
           cout << temp;
        }
        else {
            cout << "," << temp;
        }
        judge1=1;
    }
}
int main()
{
    int loc = 0;
    int judge2=0;//判断有没有真素数
    int judge=0;//判断是不是素数
    int N, M;
    cin >> N >> M;
    for (int i = N; i <= M; i++) {
        for (int j = 2; j < i; j++) {
            if (i % j == 0) {
                judge = 1;
                break;
            }
        }
        if (judge == 0) {
            RealJudge(i,loc,judge2);
            loc++;
        }
        judge = 0;
    }
    if (judge2 != 1) {
        cout << "No";
    }
}
2024/7/23 10:06
加载中...