poj3006 素数

2019-11-26  本文已影响0人  暖昼氤氲
 /*
Time:2019.11.26 
Author: Goven
type:素数 
err:
ref:
*/
#include<iostream>
#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;
}

上一篇下一篇

猜你喜欢

热点阅读