poj3006Dirichlet's Theorem on Arithmetic Progressions

今晚上就水题消遣了吧。。。。


#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;

int a,d,n,i,j,save=0;
bool sets[1500000];

int main(){
    memset(sets,0,sizeof(bool));
    sets[0]=sets[1]=true;
    for(int i=2;i<1500000;i++)
        if(!sets[i]){
            int j=2;
            while(i*j<1500000){
                sets[i*j]=true;
                j++;
            }
        }
    while(scanf("%d%d%d",&a,&d,&n),a!=0||d!=0||n!=0){
        save=0;
        if(!sets[a]) save++;
        while(save<n){
            a+=d;
            if(!sets[a]) save++;
        }
        printf("%d\n",a);
    }
    return 0;
}


你可能感兴趣的:(poj3006Dirichlet's Theorem on Arithmetic Progressions)