You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
914 B
39 lines
914 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
//判断是不是质数
|
|
bool isPrime(int n) { //最快的方法
|
|
if (n < 2) return false;
|
|
if (n == 2 || n == 3) return true;
|
|
if (n % 6 != 1 && n % 6 != 5) return false;
|
|
for (int i = 5; i <= floor(sqrt(n)); i += 6)
|
|
if (n % i == 0 || n % (i + 2) == 0)
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
int main() {
|
|
int m, n;
|
|
cin >> m >> n;
|
|
vector<int> v1;
|
|
|
|
for (int i = m; i <= n; ++i) {
|
|
if (i < 10) continue;
|
|
int shi, ge;
|
|
shi = i / 10;
|
|
ge = i % 10;
|
|
int jingxiang = ge * 10 + shi;
|
|
if (isPrime(i) && isPrime(jingxiang)) {
|
|
v1.push_back(i);
|
|
}
|
|
}
|
|
//输出结果
|
|
for (int i = 0; i < v1.size() - 1; ++i) {
|
|
cout << v1[i] << ",";
|
|
}
|
|
//输出最后一个
|
|
cout << v1[v1.size() - 1] << endl;
|
|
return 0;
|
|
}
|