#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define pi 2*acos(0.0)
const int N = 1e6;
int a[N];
void solve()
{
ll n, m, k; cin >> n >> m >> k;
ll x = n;
ll last_n1 = 3168, last_n2 = -234;
for (int _ = 1; _ <= k; _++) {
ll y = -1;
for (ll i = max(2LL, n - m); i <= n + m; i++) {
if (i == n) {
continue;
}
//cout << i << endl;
ll ans = i;
for (ll j = 2; j * j <= i; j++) {
if (i % j == 0) {
ans = j;
break;
}
}
if (ans >= y) {
y = ans;
}
}
//cout << y << endl;
if (_ % 2 == 0) {
last_n2 = n;
}
else {
last_n1 = n;
}
n = y;
if (_ % 2 == 0 && last_n2 == n) {
if (k % 2 == 0) {
cout << last_n2 << endl; return;
}
else {
cout << last_n1 << endl; return;
}
}
else if (_ % 2 == 1 && last_n1 == n) {
if (k % 2 == 1) {
cout << last_n1 << endl; return;
}
else {
cout << last_n2 << endl; return;
}
}
}
cout << n << endl;
}
int main ()
{
ios::sync_with_stdio(false); cin.tie(nullptr);
ll t = 1;
//cin >> t;
while(t--) {
solve();
}
return 0;
}