Files
python/TangDou/LuoGuBook/L4_14_0.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

29 lines
611 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}