トップ 差分 一覧 Farm ソース 検索 ヘルプ PDF RSS ログイン

2006da1.cpp

#include <iostream>
#include <cmath>

using namespace std; // おまじない

bool sosu(int x)
{
	if(x<2){
		return false;
	}else if(x==2){
		return true;
	}else if(x%2==0){
		return false;
	}else{
		bool flag=true;
		for(int i=3; i<=sqrt(x); i+=2){
			if(x%i==0){
				flag=false;
				break;
			}
		}
		if(flag) return true;
		else return false;
	}
}

main()
{
	while(true){
		int a,d,n,p;
		cin >> a >> d >> n;
		if(a==0 && d==0 && n==0) break;
		int ct=0;
		for(int i=a; ct<n; i+=d){
			if(sosu(i)){
				ct++;
				p=i;
			}
		}
		cout << p << endl;
	}
	return 0;
}