'commit'
This commit is contained in:
32
TangDou/LuoGuBook/L4_14.cpp
Normal file
32
TangDou/LuoGuBook/L4_14.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user