[P2667]超级质数
来源:互联网 发布:经商软件 编辑:程序博客网 时间:2024/05/22 14:05
原题链接
一开始想用线性筛来着
想了想没法做
后来看了题解想打表
然后觉得太偷懒了就放弃了
总之最后就搜索了
构造法
#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>#include<cmath>#include<queue>#include<vector>#include<climits>#include<string>#include<cstdlib>#define LL long long#define MOD 1000000007#define pi 3.141592653589using namespace std;int h[7]={0,1,2,3,5,7,9},n,tot,ans[90];bool prime(int x){ int i; for(i=2;i<=sqrt(x);i++) if(x%i==0) return false; return true;}void dfs(int x){ int tmp,i; if(x>n) return; tot++; ans[tot]=x; for(i=1;i<=6;i++) { tmp=x*10+h[i]; if(prime(tmp)) dfs(tmp); }}int main(){ int i; scanf("%d",&n); for(i=2;i<=5;i++) { dfs(h[i]); } sort(ans+1,ans+tot+1); printf("%d\n",tot); for(i=1;i<=tot;i++) printf("%d\n",ans[i]); return 0;}
阅读全文
0 0
- [P2667]超级质数
- P2667 超级素数
- 超级质数
- 1.5 超级肋骨质数
- luogu2667 超级质数
- 还是质数 NOJ 1732 超级暴力
- SSL P2667 呵呵
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- 质数
- nginx性能优化及测试
- CentOS 7上安装GCC
- 超级质数
- c语言static关键字
- 分布式架构核心RPC原理
- [P2667]超级质数
- sublime之less
- 软件测试黑马工程师--缺陷及用例
- Java设计模式——工厂设计模式
- 大小写字母转换
- Luogu1967 [NOIP2013] 货车运输 解题报告【Kruskal】【LCA】【倍增】
- 服务器写接口
- 实训第三周
- Linux服务器(CentOS)安装SVN(subversion)教程