poj3006 素数

 /*
Time:2019.11.26 
Author: Goven
type:素数 
err:
ref:
*/
#include
#define MAXN 1000000
using namespace std;

bool prime[MAXN];

void primeTable() {
    prime[0] = prime[1] = false;
    for (int i = 2; i < MAXN; i++) {
        prime[i] = true;
    }
    for (int i = 2; i < MAXN; i++) {
        if (prime[i]) {
            for (int j = i + i; j < MAXN; j += i) {
                prime[j] = false;
            }
        }
    }   
}

int main()
{
    int a, b, n;
    primeTable();
    while (cin >> a >> b >> n) {
        if (a == 0 && b == 0 && n == 0) break;
        while (n) {
            if (prime[a]) n--;
            a += b;
        }
        cout << a - b << endl;
    }
    return 0;
}

你可能感兴趣的:(poj3006 素数)