您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: