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.

32 lines
648 B

#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;
int m = 0;
while (i) {
m = m * 10 + i % 10;
i /= 10;
}
return m == n;
}
int main() {
//定义输出文件
//ofstream out("../LuoGuBook/L4_14.txt");
ofstream out("c:/L4_14.txt");
for (int i = 2; i <= 100000000; i++)
if (IsPrime(i) && isHuiWen(i)) out << i <<",";
//关闭输出文件
out.close();
return 0;
}