Wza999888 @ 2024-02-22 16:25:56
#include<bits/stdc++.h>
using namespace std;
int n, m;
int issu(int x) {
if (x == 1) return 0;
if (x % 2 == 0) return 0;
else {
int i;
for (i = 2; i <= sqrt(x); i++) {
if (x % i == 0) return 0;
}
return 1;
}
}
int hw(int x) {
/*int i, j;
for (i = 0, j = s.length() - 1; i <= j; i++, j--) {
if (s[i] != s[j]) return false;
}
return true;*/
int sum = 0, k = x;
while (x != 0) {
sum = sum * 10 + x % 10;
x /= 10;
}
if (sum == k) return 1;
else return 0;
}
int main() {
cin >> n >> m;
for (int i = n; i <= m; i++) {
if (n == 9989900) break;
if (hw(i) && issu(i)) cout << i << endl;
}
return 0;
}
by xiexinxin @ 2024-02-22 16:30:36
不用判断偶数
by xiexinxin @ 2024-02-22 16:31:21
@xiexinxin 2除外
by xiexinxin @ 2024-02-22 16:38:04
还有除了11的偶数位可以直接跳过(因为都会被11整除)
by xiexinxin @ 2024-02-22 16:44:32
@Wza999888
by xiexinxin @ 2024-02-22 16:48:11
其实你以后代码出了问题不知道怎么改的话可以逛逛讨论区,里面也许有相同问题的纠正
by Wza999888 @ 2024-02-22 18:09:36
@xiexinxin 谢谢dalao