#include #include #include using namespace std; const int N = 1000 * 1000 + 100; vector primes; bool isPrime[N]; void make_primes(){ fill(&isPrime[0], &isPrime[N], true); isPrime[0] = isPrime[1] = false; primes.clear(); for(int i = 2; i < N; i++){ if(isPrime[i]){ primes.push_back(i); if(i > N / i){break;} for(int j = i * i; j < N; j += i){ isPrime[j] = false; } } } } int main(){ make_primes(); while(true){ int a, d, n; cin >> a >> d >> n; if(a == 0 and d == 0 and n == 0){break;} int count = 0; for(int i = 0; ; i++){ if(isPrime[a + d * i]){ count++; } if(count == n){ cout << a + d * i << endl; break; } } } }