#include "iostream"
#include "cmath"
using namespace std;
bool is_primer(int num)
{
int i, n;
if (num == 1) return 0;
n = sqrt(double(num));
for (i = 2; i <= n; i++)
{
if (num % i == 0)
return 0;
}
return 1;
}
int main()
{
int a, d, n, count, i;
while (cin >> a >> d >> n)
{
if (a == 0 && d == 0 && n == 0) break;
count = 0;
for (i = a; ; i += d)
{
if (is_primer(i))
count++;
if (count == n)
{
cout << i << endl;
break;
}
}
}
system("pause");
}
poj 3006 Dirichlet's Theorem on Arithmetic Progressions
最新推荐文章于 2021-12-21 09:13:22 发布