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.

29 lines
611 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
//是不是质数
bool IsPrime(int n) {
for (int i = 2; i <= n / i; i++)
if (n % i == 0)return false;
return true;
}
//是不是回文数
bool isHuiWen(int n) {
int i = n;//n备份到了i,一会我们要操作i,i会变化n操持不动
int m = 0;//反向回文数结果
while (i) {
m = m * 10 + i % 10;
i /= 10;
}
return m == n;
}
int main() {
//1e8
for (int i = 5; i <= 100000000; i++)
if (IsPrime(i) && isHuiWen(i))
cout << i << ",";
return 0;
}