poj3006
普通的n^2的筛法居然比线性筛法快,不知道以后该用哪个了……
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define maxn 1000000
bool prime[maxn];
int main()
{
//freopen("D:\\t.txt", "r", stdin);
memset(prime, true, sizeof(prime));
for (int i = 3; i <= 1000; i += 2)
for (int j = 3; j <= maxn / i; j += 2)
if (prime[i])
prime[i * j] = false;
for (int i = 4; i <= maxn; i += 2)
prime[i] = false;
prime[1] = prime[0] = false;
int a, d, n;
while (scanf("%d%d%d", &a, &d, &n) != EOF && !(a == 0 && d == 0 && n == 0))
{
int p;
for (p = a; n > 0; p += d)
{
if (prime[p])
n--;
}
printf("%d\n", p - d);
}
return 0;
}