#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 (筛选法素数打表)
最新推荐文章于 2018-01-05 07:28:09 发布