如果一个数本身是素数,并且把最低位删除后得到的数仍是素数、再把最低位删除后得到的数仍是素数……如此往复,直到得到一个一位素数,我们就称它是“幸运素数”。以 233 为例:
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
A-Chin 2022-04-25 19:58关注#include <iostream> using namespace std; #include <stdio.h> bool pri(int N); int main() { int X; cin>>X; int i = 1; int judge = 1; while(1) { if (pri(X / i) == false) { judge = 0; break; } i *= 10; if (X <= i) break; } if (judge == 1) cout<<X<<"是幸运素数"<<endl; else cout<<X<<"不是幸运素数"<<endl; return 0; } bool pri(int N) { if (N == 1) return true; int count = 0; for (int j = 2; j < N; ++j) { if (N % j == 0) { count += 1; break; } } if (count == 0) return true; return false; }本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录