http://poj.org/problem?id=3006
给一个等差数列,求其中的第n个质数,答案保证不超过1e6。n还特别小?!!!
埃筛之后暴力。
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
bool np[1000005];
int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
#endif // Yinku
np[1] = 1;
for(int i = 2; i <= 100000; ++i) {
if(np[i])
continue;
else {
for(int j = i + i; j <= 1000000; j += i)
np[j] = 1;
}
}
int a, d, n;
while(cin >> a >> d >> n) {
if(a == 0 && d == 0 && n == 0)
break;
while(1) {
if(!np[a])
n--;
if(n == 0) {
cout << a << endl;
break;
}
a += d;
}
}
}
POJ - 3006 - Dirichlet's Theorem on Arithmetic Progressions = 水题
原文:https://www.cnblogs.com/Inko/p/11723374.html