#include using namespace std; bool nprimes[1000001]; int main(){ memset(nprimes,0,sizeof(nprimes)); nprimes[1] = true; for(int i=2;i<=1000000;i++){ if(!nprimes[i]){ for(int j=2;i*j<=1000000;j++){ nprimes[i*j] = true; } } } int a,d,n; while(cin>>a>>d>>n,a||d||n){ int idx = 0; int t = a; while(1){ if(!nprimes[t]) idx++; if(idx==n) break; t += d; } cout << t << endl; } }