POJ 3006 Dirichlet's Theorem on Arithmetic Progressions (筛选法素数打表)
2013-04-13 11:27
513 查看
#include <iostream> #include <cstdio> using namespace std; const int maxn=1000100; bool isP[maxn]; void init(){ for (int i=2;i<maxn;++i){ isP[i]=1; } for (int i=2;i<maxn;++i){ if(isP[i]){ for (int j=2;j*i<maxn;++j){ isP[i*j]=0; } } } } int a,b,n; int main(){ init(); while (scanf("%d%d%d",&a,&b,&n)==3){ if(!a&&!b&&!n)break; int ans=a; while (n){ if(isP[a]){ n--; ans=a; } a+=b; } printf("%d\n",ans); } return 0; }
相关文章推荐
- POJ 3006 Dirichlet's Theorem on Arithmetic Progressions 素数的判断 筛选法
- POJ 3006 Dirichlet's Theorem on Arithmetic Progressions ( 素数、筛选)
- POJ 3006 Dirichlet's Theorem on Arithmetic Progressions 素数的判断 筛选法
- POJ 2739 素数筛选法打表
- Poj 2689 Prime Distance ----大区间素数筛选
- poj 2689(区间素数筛选)
- poj - 3006 素数表
- POJ 3126 Prime Path (素数筛选+bfs)
- poj2739 Sum of Consecutive Prime Numbers 尺取法 素数打表
- poj 3006 Dirichlet's Theorem on Arithmetic Progressions 【素数筛】
- poj1365---素数打表和质因子分解
- POJ 2739 素数筛选
- POJ 2689 Prime Distance(筛选两次素数)
- poj 3518(筛选素数)
- 杭电 4548 美素数 (筛选素数 打表 )
- POJ 3126 Prime Path(素数打表+bfs)
- 筛选素数,打表,区间内特定元素的个数
- poj1595 素数打表
- poj2909 欧拉素数筛选
- POJ - 2262 - Goldbach's Conjecture(筛选素数)