超级质数
来源:互联网 发布:经商软件 编辑:程序博客网 时间:2024/05/02 08:17
QAQ
一个数是超级质数是要把这个数/10分解判断,那么反过来,我们直接从素数的基础上造超级质数,但是我们造出来的并不一定是素数,所以要有个素数判断,使用最简单的sqrt(n)判断
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>using namespace std;bool cf(int x){ if(x==1) return 0; if(x==2) return 1; for(int i=2;i<=sqrt(x);i++) if(x%i==0) return 0; return 1;}int num[9999],cnt;int n;void dfs(long long x){ if(x>n) return; int d=cf(x); if(x&&d) num[++cnt]=x; if(d)//造的前提是这个数是素数 { dfs(x*10+1); dfs(x*10+2); dfs(x*10+3); dfs(x*10+5); dfs(x*10+7); dfs(x*10+9);//末尾是4,6,8的数肯定不符合要求 }}int main(){ scanf("%d",&n); dfs(0); sort(num+1,num+cnt+1);//排序,从小到大输出 printf("%d\n",cnt); for(int i=1;i<=cnt;i++) printf("%d\n",num[i]);}
阅读全文
0 0
- 超级质数
- 1.5 超级肋骨质数
- [P2667]超级质数
- luogu2667 超级质数
- 还是质数 NOJ 1732 超级暴力
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- linux 数据库文件迁移步骤详解
- c语言sizeof关键字
- lable标签
- nginx性能优化及测试
- CentOS 7上安装GCC
- 超级质数
- c语言static关键字
- 分布式架构核心RPC原理
- [P2667]超级质数
- sublime之less
- 软件测试黑马工程师--缺陷及用例
- Java设计模式——工厂设计模式
- 大小写字母转换
- Luogu1967 [NOIP2013] 货车运输 解题报告【Kruskal】【LCA】【倍增】