/*
 * Copyright (c) 2006 Kamo Hiroyasu
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 * An answer to
 *  Problem A Dirichlet's Theorem on Arithmetic Progressions
 *  Author: Kamo Hiroyasu <wd@ics.nara-wu.ac.jp>
 */

#include <stdio.h>
#include <stdlib.h>

int
isprime(int x)
{
	int	i, d;

	if (x < 6) {
		switch (x) {
		case 2:
		case 3:
		case 5:
			return 1;
		default:
			return 0;
		}
	}
	switch (x % 6) {
	case 0:
	case 2:
	case 3:
	case 4:
		return 0;
	}
	for (i = 5, d = 2; i * i <= x; i += d, d = 6 - d) {
		if (x % i == 0)
			return 0;
	}
	return 1;
}

int
nth_prime(int a, int d, int n)
{
	int	i;

	for (i = 0;;) {
		if (isprime(a)) {
			i ++;
		}
		if (i >= n) break;
		a += d;
	}
	return a;
}

main(int argc, char *argv[])
{
	int	a, d, n;
	const char	*path;

	switch (argc) {
	case 2:
		path = argv[1];
		if (freopen(path, "r", stdin) == NULL) {
			perror(path);
			return 2;
		}
	case 1:
		break;
	default:
		fprintf(stderr, "%s: too many arguments\n", argv[0]);
		return 1;
	}
	while (scanf("%d%d%d", &a, &d, &n) == 3 && n != 0) {
		printf("%d\n", nth_prime(a, d, n));
	}
	return 0;
}
