Orac is studying number theory, and he is interested in the properties of divisors.

For two positive integers $a$ and $b$, $a$ is a divisor of $b$ if and only if there exists an integer $c$, such that $a\cdot c=b$.

For $n \ge 2$, we will denote as $f(n)$ the smallest positive divisor of $n$, except $1$.

For example, $f(7)=7,f(10)=2,f(35)=5$.

For the fixed integer $n$, Orac decided to add $f(n)$ to $n$. 

For example, if he had an integer $n=5$, the new value of $n$ will be equal to $10$. And if he had an integer $n=6$, $n$ will be changed to $8$.

Orac loved it so much, so he decided to repeat this operation several times.

Now, for two positive integers $n$ and $k$, Orac asked you to add $f(n)$ to $n$ exactly $k$ times (note that $n$ will change after each operation, so $f(n)$ may change too) and tell him the final value of $n$.

For example, if Orac gives you $n=5$ and $k=2$, at first you should add $f(5)=5$ to $n=5$, so your new value of $n$ will be equal to $n=10$, after that, you should add $f(10)=2$ to $10$, so your new (and the final!) value of $n$ will be equal to $12$.

Orac may ask you these queries many times.


-----Input-----

The first line of the input is a single integer $t\ (1\le t\le 100)$: the number of times that Orac will ask you.

Each of the next $t$ lines contains two positive integers $n,k\ (2\le n\le 10^6, 1\le k\le 10^9)$, corresponding to a query by Orac.

It is guaranteed that the total sum of $n$ is at most $10^6$. 


-----Output-----

Print $t$ lines, the $i$-th of them should contain the final value of $n$ in the $i$-th query by Orac.


-----Example-----
Input
3
5 1
8 2
3 4

Output
10
12
12



-----Note-----

In the first query, $n=5$ and $k=1$. The divisors of $5$ are $1$ and $5$, the smallest one except $1$ is $5$. Therefore, the only operation adds $f(5)=5$ to $5$, and the result is $10$.

In the second query, $n=8$ and $k=2$. The divisors of $8$ are $1,2,4,8$, where the smallest one except $1$ is $2$, then after one operation $8$ turns into $8+(f(8)=2)=10$. The divisors of $10$ are $1,2,5,10$, where the smallest one except $1$ is $2$, therefore the answer is $10+(f(10)=2)=12$.

In the third query, $n$ is changed as follows: $3 \to 6 \to 8 \to 10 \to 12$.

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
import math
t = int(input())

def f(n):
	temp = int(math.modf(math.sqrt(n))[1])
	for i in range(2, temp + 1):
		if n % i == 0:
			return i
	return n
for i in range(t):
	temp = input().split()
	n = int(temp[0])
	k = int(temp[1])
	smallestFactor = f(n)
	if n % 2 != 0 and smallestFactor % 2 != 0:
		print(n + smallestFactor + 2 * (k - 1))
	else:
		print(n + k * smallestFactor)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n + 2 * (k - 1)
	for j in range(2, n + 1):
		if n % j == 0:
			break
	ans += j
	print(ans)


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	(n, k) = (a[0], a[1])
	key = 0
	for p in range(2, n + 1):
		if n % p == 0:
			key = 1
			break
	if key == 0:
		print(2 * n + 2 * (k - 1))
	elif p == 2:
		print(n + p * k)
	else:
		print(n + p + 2 * (k - 1))


for test in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		for i in range(3, int(n ** 0.5) + 1, 2):
			if n % i == 0:
				n += i
				break
		else:
			n += n
		print(n + 2 * (k - 1))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	c = n
	if c % 2 == 0:
		c += k * 2
	else:
		for j in range(3, c + 1):
			if c % j == 0:
				c += j
				c += (k - 1) * 2
				break
	print(c)


z = input
from math import ceil, log, gcd
n1 = int(z())

def p(x):
	c = 0
	for i in range(2, x):
		if x % i == 0:
			c = 1
			break
	if c == 1:
		return i
	else:
		return x
for _ in range(n1):
	(a, b) = map(int, input().split())
	ans = p(a)
	print(ans + (b - 1) * 2 + a)


import math
inp = lambda : map(int, input().split())

def first_divisor(num):
	for i in range(3, int(math.sqrt(num)) + 1):
		if num % i == 0:
			return i
	return num
t = int(input())
for i in range(t):
	(n, k) = inp()
	if n % 2 == 0:
		print(n + k * 2)
	else:
		print(n + first_divisor(n) + 2 * (k - 1))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		for i in range(2, n + 1):
			if n % i == 0:
				k -= 1
				n += i
				break
		print(n + 2 * k)


def give(n):
	i = 2
	while i * i <= n:
		if n % i == 0:
			return i
		i += 1
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(n + give(n) + 2 * (k - 1))


import math

def find_smallest_factor(n):
	if n % 2 == 0:
		return 2
	sqrt_n = int(math.sqrt(n)) + 1
	maxx = int(sqrt_n / 2) + 1
	for f in range(1, maxx):
		target = 2 * f + 1
		if n % target == 0:
			return target
	return n
trails = int(input())
answer_list = []
for x in range(trails):
	numbers = input()
	numbers = numbers.split(' ')
	first = int(numbers[0])
	second = int(numbers[1])
	first += find_smallest_factor(first)
	first += (second - 1) * 2
	answer_list.append(first)
for q in answer_list:
	print(q)


def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = int(input())
while t:
	(n, k) = map(int, input().split())
	for i in range(k):
		tmp = smallestDivisor(n)
		if tmp == 2:
			n += 2 * (k - i)
			break
		n += tmp
	print(n)
	t -= 1


def evenN(n, k):
	return n + k * 2

def factors(n, k):
	if n % 2 == 0:
		return evenN(n, k)
	else:
		c = 0
		for j in range(k):
			for i in range(2, n + 1):
				if n % i == 0:
					n += i
					c += 1
					break
			if n % 2 == 0:
				return evenN(n, k - c)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().rstrip().split())
	result = factors(n, k)
	print(result)


def f(A):
	i = 2
	while i * i <= A:
		if A % i == 0:
			return i
		i += 1
	return A
for q in range(int(input())):
	(a, b) = map(int, input().split())
	res = a
	while a % 2 == 1 and b > 0:
		res = f(a) + a
		b -= 1
		a = res
	if b > 0:
		res += b * 2
	print(res)


import math

def div(n):
	for i in range(3, int(math.sqrt(n) + 1), 2):
		if n % i == 0:
			return i
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + 2 * (k - 1) + div(n))


tc = int(input().strip())
lst = 10 ** 6 + 1
prime_sieve = [True for i in range(lst)]
prime_sieve[0] = prime_sieve[1] = False
i = 2
while i * i <= lst:
	if prime_sieve[i]:
		for j in range(2 * i, lst, i):
			prime_sieve[j] = False
	i += 1
prime_sieve = [i for i in range(len(prime_sieve)) if prime_sieve[i] == True]

def solve():
	(n, k) = map(int, input().strip().split())
	for i in prime_sieve:
		if n % i == 0:
			break
	print(i + n + 2 * (k - 1))
for t in range(tc):
	solve()


def sd(i):
	j = 3
	while j * j <= i:
		if i % j == 0:
			return j
			r = 1
			break
		j += 2
	return i
t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		n += 2 * k
	else:
		n += sd(n)
		n += 2 * (k - 1)
	print(n)
	t -= 1


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	for i in range(2, a[0] + 1):
		if a[0] % i == 0:
			a[0] = a[0] + i
			break
	print(a[0] + 2 * (a[1] - 1))


from sys import stdin
input = stdin.readline
nax = 1000001
sieve = [0] * nax
for i in range(2, nax):
	if not sieve[i]:
		for j in range(i, nax, i):
			if not sieve[j]:
				sieve[j] = i
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n & 1:
		n += sieve[n]
		print(n + 2 * (k - 1))
	else:
		print(n + 2 * k)


t = int(input())
i = 0
for i in range(t):
	var = 0
	(n, k) = map(int, input().split())
	for i in range(2, n + 1):
		if n % i == 0:
			var = i
			break
	var += n
	ans = (k - 1) * 2 + var
	print(ans)


def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			q.append(p)
q = []
SieveOfEratosthenes(10 ** 6)
for i in range(0, int(input())):
	(n, k) = list(map(int, input().split()))
	j = 0
	if n % 2 == 0:
		n = n + k * 2
	else:
		while j < k and n % 2 != 0:
			for m in range(0, len(q)):
				if n % q[m] == 0:
					n = n + q[m]
					break
			j = j + 1
		if j < k:
			n = n + 2 * (k - j)
	print(n)


from math import sqrt

def ri():
	return int(input())

def ria():
	return list(map(int, input().split()))

def f(n):
	if n % 2 == 0:
		return 2
	d = 3
	sqr = int(sqrt(n))
	while d <= sqr and n % d != 0:
		d += 2
	if n % d == 0:
		return d
	return n

def main():
	for _ in range(ri()):
		(n, k) = ria()
		print(n + f(n) + 2 * (k - 1))
main()


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

def divisors(N: int) -> set:
	from math import sqrt
	s = {1, N}
	for i in range(2, int(sqrt(N)) + 1):
		if N % i == 0:
			s.add(i)
			s.add(N // i)
	return s
for _ in range(INT()):
	(N, K) = MAP()
	ans = N
	while 1:
		K -= 1
		divs = sorted(divisors(ans))
		ans += divs[1]
		if divs[1] == 2:
			break
	ans += 2 * K
	print(ans)


def func(n):
	j = 3
	while True:
		if n % j == 0:
			return j
		else:
			j += 1
t = int(input())
res = []
for i in range(t):
	(n, k) = map(int, input().split(' '))
	if n % 2 == 0:
		res.append(n + 2 * k)
	else:
		res.append(n + func(n) + 2 * (k - 1))
for i in res:
	print(i)


import sys
import math

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]
t = int(input())
for q in range(t):
	(n, k) = inputnums()
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		for i in range(3, n + 1):
			if n % i == 0:
				n += i
				break
			else:
				i += 1
		print(n + 2 * k - 2)


import math
import collections
from sys import stdin, stdout
T = int(stdin.readline())
for _ in range(T):
	(n, k) = list(map(int, stdin.readline().split()))
	ans = 0
	for i in range(n - 1):
		if n % (i + 2) == 0:
			ans += i + 2
			break
	ans += 2 * (k - 1)
	print(ans + n)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 1:
		z = 0
		for j in range(2, int(n ** 0.5) + 1):
			if n % j == 0 and n != 1:
				z = j
				break
		if z == 0 and n != 1:
			z = n
		n += z
		k -= 1
	n = n + k * 2
	print(n)


def smallestdivisor(n):
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	jj = 0
	if n % 2 != 0:
		jj += smallestdivisor(n)
		k -= 1
		n += jj
	n += 2 * k
	print(n)


t = int(input())
for q in range(t):
	(n, k) = map(int, input().split())
	flag = 0
	for i in range(2, int(n ** 0.5) + 2):
		if n % i == 0:
			flag = 1
			n += i
			break
	if flag == 0:
		print(2 * n + (k - 1) * 2)
	else:
		print(n + (k - 1) * 2)


isSimple = [0] * 1000005
for i in range(2, len(isSimple)):
	if isSimple[i] == 0:
		for j in range(i * 2, len(isSimple), i):
			isSimple[j] = 1
listSimpe = []
for i in range(2, len(isSimple)):
	if isSimple[i] == 0:
		listSimpe.append(i)
for t in range(int(input())):
	(n, k) = map(int, input().split())
	for i in range(2, n + 1):
		if n % i == 0:
			n += i
			break
	answer = n + (k - 1) * 2
	print(answer)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	n1 = n
	if n % 2 != 0:
		j = 3
		while j * j <= n1:
			if n1 % j == 0:
				n1 = n1 + j
				k = k - 1
				break
			j = j + 2
		if n1 == n:
			n1 = n1 + n1
			k = k - 1
	print(n1 + 2 * k)


T = int(input())
for _ in range(0, T):
	x = 0
	(N, K) = map(int, input().split())
	if N % 2 == 0:
		print(N + 2 * K)
	else:
		for i in range(2, N + 1):
			if N % i == 0:
				N = N + i
				break
		print(N + 2 * (K - 1))


import sys
readline = sys.stdin.readline

def solve():
	(N, K) = map(int, readline().split())
	if N % 2 == 1:
		for i in range(3, N + 1):
			if N % i == 0:
				break
		N = N + i
		K -= 1
	ans = N + K * 2
	print(ans)
T = int(readline())
for i in range(T):
	solve()


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]
spf_sieve()

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	(n, k) = int_array()
	if n % 2 != 0:
		n += spf[n]
		k -= 1
	n += 2 * k
	print(n)


n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split()))
	r = a
	if r % 2 == 0:
		r += 2 * b
	else:
		for k in range(2, a + 1):
			if r % k == 0:
				r += k
				break
		r += 2 * (b - 1)
	print(r)


from functools import reduce

def factors(n):
	return list(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + sorted(factors(n))[1] + 2 * (k - 1))


T = int(input())
while T:
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		x = n + 2 * k
	else:
		for i in range(3, n + 1):
			if n % i == 0:
				x = n + i + 2 * (k - 1)
				break
	print(x)
	T = T - 1


import math

def get_num():
	return list(map(int, input().rstrip().split()))

def rotate(my_list, num):
	return my_list[num:] + my_list[:num]

def divisor(num):
	i = 2
	while i <= num:
		if num % i == 0:
			return i
		i += 1

def main():
	num = int(input())
	for i in range(num):
		mynum = get_num()
		n = mynum[0]
		k = mynum[1]
		if n % 2 == 0:
			print(n + 2 * k)
		else:
			print(n + 2 * (k - 1) + divisor(n))
main()


import functools

@functools.lru_cache(maxsize=None)
def f(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def solve(n, k):
	f_n = f(n)
	return n + f_n + (k - 1) * 2

def main():
	T = int(input())
	for _ in range(T):
		(n, k) = map(int, input().split())
		print(solve(n, k))
main()


t = int(input())

def make_divisors(n):
	for i in range(2, n + 1):
		if n % i == 0:
			divisors = i
			break
	return divisors
ans = [0] * t
for i in range(t):
	(n, k) = map(int, input().split())
	n += make_divisors(n)
	n += 2 * (k - 1)
	ans[i] = n
for i in range(t):
	print(ans[i])


import sys
input = sys.stdin.readline

def prime_list(n):
	sieve = [True] * (n + 1)
	m = int(n ** 0.5)
	for i in range(2, m + 1):
		if sieve[i] == True:
			for j in range(i + i, n + 1, i):
				sieve[j] = False
	list = []
	for i in range(2, n + 1):
		if sieve[i] == True:
			list.append(i)
	return list

def lsf(N):
	fac = 0
	if N in P:
		return N
	for i in P:
		if N % i == 0:
			fac = i
			break
	return fac
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	P = prime_list(n)
	for i in range(k):
		if n % 2 == 0:
			n = n + 2 * (k - i)
			break
		fac = lsf(n)
		n = n + fac
	print(n)


t = int(input())
ans = []
for i in range(t):
	(n, k) = map(int, input().split())
	b = 0
	for i in range(k):
		if n % 2 == 0:
			n = n + 2 * (k - b)
			ans.append(n)
			break
		else:
			b += 1
			for j in range(2, n + 1):
				if n % j == 0:
					n = j + n
					break
		if i == k - 1:
			print(n)
for i in ans:
	print(i)


from math import sqrt

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	z = smallestDivisor(n)
	n = n + z
	n = n + 2 * (k - 1)
	print(n)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	x = 0
	for t in range(2, n + 1):
		if n % t == 0:
			x = t
			break
	if x == n:
		x *= 2
		x += 2 * (m - 1)
		print(x)
	elif x % 2 == 0:
		x = 2 * m + n
		print(x)
	else:
		x += n
		x += 2 * (m - 1)
		print(x)


def getSmallest(n):
	if n % 2 == 0:
		return 2
	else:
		i = 3
		while i < n / 2:
			if n % i == 0:
				return i
			i += 2
		return n
for i in range(int(input())):
	(n, k) = map(int, input().split())
	small = getSmallest(n)
	n += small
	n += (k - 1) * 2
	print(n)


try:
	T = int(input())
	for i in range(T):
		(N, K) = input().split()
		N = int(N)
		K = int(K)
		if N % 2 == 0:
			N = N + 2 * K
		else:
			for j in range(2, N + 1):
				if N % j == 0:
					N += j
					break
			N = N + 2 * (K - 1)
		print(N)
except Exception as e:
	print(e)


t = int(input())
while t:
	(n, k) = list(map(int, input().split()))
	if n % 2 == 0:
		print(int(n + 2 * k))
	else:
		c = 2
		while n % c != 0:
			c += 1
		print(int(n + c + 2 * (k - 1)))
	t -= 1


import sys
from math import ceil
from itertools import islice, cycle
from collections import Counter, defaultdict
import math
stdin = sys.stdin
t = stdin.readline()
t = int(t)

def get_divisor(n):
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		if n % i == 0:
			return i
for test in range(t):
	(n, k) = stdin.readline().strip().split()
	(n, k) = (int(n), int(k))
	divisor = get_divisor(n) or n
	print(n + divisor + 2 * (k - 1))


import math

def prime(n):
	if n % 2 == 0:
		return False
	i = 3
	while i <= math.sqrt(n):
		if n % i == 0:
			return False
		i += 1
	return True
test = int(input())
while test > 0:
	(n, k) = [int(x) for x in input().split()]
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		if prime(n) is True:
			n = n + n
		else:
			i = 2
			while i <= math.sqrt(n):
				if n % i == 0:
					n = n + i
					break
				i += 1
		print(n + 2 * (k - 1))
	test = test - 1


def A(n):
	for i in range(2, int(n ** 0.5) + 2):
		if n % i == 0:
			return i
	return n
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k == 1:
		print(n + A(n))
	if k != 1:
		a = n + A(n)
		print(a + 2 * (k - 1))


def f(n, k):
	if n % 2 == 0:
		n = n + 2 * k
	else:
		for i in range(2, int(pow(n, 0.5)) + 1):
			if n % i == 0:
				x = i
				break
		else:
			x = n
		n = n + x
		k = k - 1
		if k != 0:
			n = n + 2 * k
	return n
t = int(input())
for i in range(0, t):
	(n, k) = map(int, input().split())
	print(f(n, k))


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	while k:
		if n % 2 == 0:
			n = n + 2 * k
			k = 0
			break
		else:
			for i in range(2, n + 1):
				if n % i == 0:
					n = n + i
					k -= 1
					break
	print(n)


import sys
from os import path
if path.exists('C:/Users/prana/Desktop/sublime/input.txt'):
	sys.stdin = open('C:/Users/prana/Desktop/sublime/input.txt', 'r')
	sys.stdout = open('C:/Users/prana/Desktop/sublime/output.txt', 'w')

def sd(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def solve():
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	n += sd(n) + (k - 1) * 2
	print(n)
T = 1
T = int(input())
for _ in range(1, T + 1):
	print('Case #', _, file=sys.stderr)
	solve()


for _ in range(int(input())):
	(n, k) = [int(j) for j in input().split()]
	if n % 2 == 0:
		print(n + k * 2)
	else:
		i = 3
		while n % i != 0:
			i = i + 2
		n = n + i
		k = k - 1
		while k != 0:
			if n % 2 == 0:
				n = n + k * 2
				break
			elif k != 0:
				n = n + i
				k = k - 1
		print(n)


t = int(input())
dicti = {}
p = []
for i in range(t):
	(n, k) = map(int, input().split(' '))
	while k > 0:
		dp = 0
		d2 = 0
		d3 = 0
		c1 = 1
		c2 = 1
		if n in dicti.keys():
			n = n + dicti[n]
			k = k - 1
		else:
			if n in p:
				dp = 1
				break
			if n % 2 == 0:
				d2 = 1
				break
			elif n % 3 == 0:
				d3 = 1
				break
			else:
				z = 5
				while z * z <= n:
					if n % z == 0:
						c1 = 0
						break
					if n % (z + 2) == 0:
						c2 = 0
						break
					z += 6
				if c1 == 0:
					dicti[n] = z
					n = n + z
				elif c2 == 0:
					dicti[n] = z + 2
					n = n + z + 2
				else:
					dp = 1
					p.append(n)
					break
			k = k - 1
	if dp == 1:
		print(n + n + 2 * (k - 1))
	elif d2 == 1:
		print(n + 2 * k)
	elif d3 == 1:
		print(n + 3 + 2 * (k - 1))
	else:
		print(n)


def res(n, k, d):
	if n % 2 == 0:
		return int(n + k * 2)
	elif d.get(n):
		return 2 * n + (k - 1) * 2
	else:
		x = 3
		while n % x != 0:
			x += 2
		return n + x + (k - 1) * 2

def SieveOfEratosthenes(n):
	d = {}
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			d[p] = 1
	return d
t = int(input())
d = SieveOfEratosthenes(10 ** 6)
for _ in range(t):
	(n, k) = map(int, input().split())
	print(res(n, k, d))


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def case():
	(n, k) = li()
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		p = 1
		for i in range(2, int(math.sqrt(n)) + 2):
			if n % i == 0 and i != 1:
				p = i
				break
		if p == 1:
			p = n
		print(n + p + 2 * (k - 1))
for _ in range(int(input())):
	case()


for i in range(int(input())):
	(n, k) = (int(i) for i in input().split())
	for i in range(2, n + 1):
		if n % i == 0:
			divisor = i
			break
	print(n + divisor + (k - 1) * 2)


mod = int(1000000000.0) + 7

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def ip():
	return int(input())

def Ip():
	return map(int, input().split())
from math import pow
for _ in range(0, int(input())):
	(n, k) = Ip()
	if n % 2 == 0:
		ans = n + k * 2
	else:
		k -= 1
		n += smallestDivisor(n)
		ans = n + k * 2
	print(ans)


import sys
agGK = int(input())
for ee in range(agGK):

	def ord(g):
		f = int(g ** 0.5)
		for i in range(2, f + 1):
			if g % i == 0:
				return i
		return g
	(n, k) = map(int, input().split())
	for j in range(k):
		if n % 2 == 0:
			n = n + (k - j) * 2
			break
		else:
			n += ord(n)
	print(n)


def leastPrimeFactor(n):
	least_prime = [0] * (n + 1)
	least_prime[1] = 1
	for i in range(2, n + 1):
		if least_prime[i] == 0:
			least_prime[i] = i
			for j in range(2 * i, n + 1, i):
				if least_prime[j] == 0:
					least_prime[j] = i
	return least_prime
f = leastPrimeFactor(1000000)
t = int(input())
for tc in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + f[n] + 2 * (k - 1))


import math
t = int(input())

def diff(x):
	for i in range(3, int(n ** 0.5) + 4):
		if x % i == 0:
			return i
	return x
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		r = diff(n)
		print(n + r + (k - 1) * 2)


import math
import sys

def prime(n):
	if n == 1:
		return 0
	if n == 2 or n == 3:
		return (1, n)
	if n % 2 == 0:
		return (0, 2)
	if n % 3 == 0:
		return (0, 3)
	for i in range(5, int(math.sqrt(n)) + 1, 6):
		if n % i == 0:
			return (0, i)
		if n % (i + 2) == 0:
			return (0, i + 2)
	return (1, n)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(isPrime, smalldiv) = prime(n)
	if isPrime:
		print(2 * n + (k - 1) * 2)
	else:
		print(n + smalldiv + (k - 1) * 2)


import math

def f(n):
	for k in range(2, math.floor(math.sqrt(n)) + 1):
		if n % k == 0:
			return k
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k < 2:
		print(n + f(n))
	else:
		print(n + f(n) + 2 * (k - 1))


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	num = []
	for i in range(t):
		n = list(map(int, input().split()))
		num.append(n)
	for temp in num:
		(n, k) = (temp[0], temp[1])
		if n % 2 == 0:
			print(n + k * 2)
		else:
			m = 0
			for i in range(3, int(math.sqrt(n)) + 1):
				if n % i == 0:
					m = i
					break
			if m == 0:
				print(2 * n + (k - 1) * 2)
			else:
				print(n + m + (k - 1) * 2)
main()


from math import *
for u in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		x = 1
		for i in range(2, int(sqrt(n)) + 1):
			if n % i == 0:
				x = i
				break
		if x == 1:
			x = n
		print(x + n + (k - 1) * 2)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	y -= 1
	i = 0
	for i in range(2, x + 1):
		if x % i == 0:
			break
	x = x + i + 2 * y
	print(x)


import math

def printDivisors(n):
	arr = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				arr.append(i)
			else:
				arr.append(i)
				arr.append(n // i)
		i = i + 1
	return arr
t = int(input())
for test in range(t):
	(n, k) = map(int, input().split())
	arr = printDivisors(n)
	arr.sort()
	print(n + arr[1] + 2 * (k - 1))


def solve(n, k):
	if n % 2 == 0:
		return n + k * 2
	for i in range(3, 3000):
		if n % i == 0:
			fn = i
			break
	else:
		fn = n
	return n + (k - 1) * 2 + fn
strr = input()
for _ in range(int(strr)):
	strr = input()
	(n, k) = [int(x) for x in strr.split()]
	print(solve(n, k))


t = int(input())
for v in range(t):
	(n, k) = map(int, input().split())
	i = 2
	flag = 0
	while i * i <= n:
		if n % i == 0:
			flag = 1
			break
		i += 1
	if flag == 1:
		n = n + i
	else:
		n = n + n
	n = n + 2 * (k - 1)
	print(n)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	m = k
	for _ in range(k):
		c = 0
		if n % 2 == 0:
			n += 2 * m
			break
		else:
			for i in range(3, int(math.sqrt(n)) + 1, 2):
				if n % i == 0:
					n += i
					c = 1
					m -= 1
					break
		if c == 0:
			n += n
			m -= 1
	print(n)


num_cases = int(input())
memo = {}

def f(n):
	if n not in memo:
		divisor = 2
		while True:
			if n % divisor == 0:
				memo[n] = divisor
				break
			divisor += 1
	return memo[n]
for _ in range(num_cases):
	(n, k) = list(map(int, input().split()))
	r = n
	for idx in range(k):
		if r % 2 == 0:
			r += 2 * (k - idx)
			break
		r += f(r)
	print(r)


I = input
pr = print

def main():
	for _ in range(int(I())):
		(n, k) = map(int, I().split())
		if n & 1:
			for i in range(3, n + 1, 2):
				if not n % i:
					pr(f'{n + i + 2 * (k - 1)}')
					break
		else:
			pr(f'{n + 2 * k}')
main()


from math import sqrt

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def main():
	t = int(input())
	for i in range(t):
		solve()

def solve():
	(n, k) = list(map(int, input().split(' ')))
	current = n
	total = 0
	total = current + smallestDivisor(current) + 2 * (k - 1)
	print(total)
main()


import math

def f(n):
	if n % 2 == 0:
		return n + 2
	i = 3
	m = math.sqrt(n)
	m = int(m)
	while i <= m:
		if n % i == 0:
			return n + i
		i += 2
	return 2 * n
t = int(input())
for i in range(t):
	nk = list(map(int, input().strip().split()))
	n = nk[0]
	k = nk[1]
	n = f(n)
	k -= 1
	if k != 0:
		n = n + 2 * k
	print(n)


def small_divisor(num):
	for i in range(2, num + 1):
		if num % i == 0:
			smallest = i
			break
	return smallest
for _ in range(int(input())):
	number_input = input().split()
	(n, k) = map(int, number_input)
	sum = n
	if n % 2 == 0:
		sum = n + 2 * k
	else:
		first_step = small_divisor(n)
		sum = first_step + n + (k - 1) * 2
	print(sum)


t = int(input())
for i in range(t):
	(n1, k1) = input().split(' ')
	n = int(n1)
	k = int(k1)
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		for i in range(3, n + 1, 2):
			if n % i == 0:
				break
		print(n + i + 2 * (k - 1))


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def pat(n):
	return n * (3 * n + 1) // 2

def f(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def foo():
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		n += k * f(n)
		print(n)
	else:
		n1 = n + f(n)
		ans = n1 + (k - 1) * f(n1)
		print(ans)
t = inp()
for i in range(t):
	foo()


q = int(input())
for _ in range(q):
	(n, k) = map(int, input().split())
	if n % 2:
		for d in range(3, n + 1):
			if n % d == 0:
				n += d
				k -= 1
				break
	n += k * 2
	print(n)


def f(a):
	j = 3
	ans = 0
	while j * j <= a:
		if a % j == 0:
			ans += 1
			return j
		j += 2
	if ans == 0:
		return a
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	if n % 2 == 0:
		ans = n + 2 * k
	else:
		ans = n + f(n) + 2 * (k - 1)
	print(ans)


def get_prime(x):
	if x == 1:
		return x
	else:
		d = 2
		prime = x
		while d * d <= x:
			if x % d == 0:
				prime = d
				break
			d += 1
		return prime
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(n + get_prime(n) + 2 * (k - 1))


def f(n):
	if n & 1 == 0:
		return 2
	k = 3
	while 1:
		if n % k == 0:
			return k
		k += 2
for cas in range(int(input())):
	(a, b) = map(int, input().split())
	if a & 1:
		a += f(a)
		b -= 1
	print(a + 2 * b)


from sys import stdin, gettrace
from math import sqrt
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():

	def solve():
		(n, k) = map(int, input().split())
		for i in range(2, int(sqrt(n)) + 1):
			if n % i == 0:
				n += i
				break
		else:
			n *= 2
		n += 2 * (k - 1)
		print(n)
	q = int(input())
	for _ in range(q):
		solve()
main()


import math

def small(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		temp = small(n)
		if k == 1:
			print(n + temp)
		else:
			print(n + temp + 2 * (k - 1))


from math import *
from random import *
for t in range(int(input())):
	(n, k) = map(int, input().split())
	f = False
	for i in range(2, ceil(sqrt(n)) + 1):
		if n % i == 0:
			print(n + i + 2 * (k - 1))
			f = True
			break
	if not f:
		print(n + n + 2 * (k - 1))


from math import sqrt

def min_divisor(n):
	i = 2
	while n % i != 0:
		if i >= sqrt(n):
			return n
		i += 1
	return i
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	a += int(min_divisor(a))
	a += 2 * (b - 1)
	print(a)


def isPrime(n):
	for i in range(3, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			l = [False, i]
			return l
	l = [True, n]
	return l
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		ans = isPrime(n)
		if ans[0] == True:
			print(n * 2 + (k - 1) * 2)
		else:
			print(n + ans[1] + (k - 1) * 2)


def is_prime(p):
	if p == 1:
		return False
	for i in range(2, int(p ** 0.5) + 1):
		if p % i == 0:
			return False
	return True
q = int(input())
for i in range(q):
	(n, k) = map(int, input().split())
	if is_prime(n):
		n += n
		print(n + (k - 1) * 2)
	elif n % 2 == 1:
		p = 2
		while n % p:
			p += 1
		print(n + p + (k - 1) * 2)
	else:
		print(n + k * 2)


a = []
for w in range(3, 1000000, 2):
	a.append(w)
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		n += 2 * k
		print(n)
	else:
		for x in range(len(a)):
			if n % a[x] == 0:
				n += a[x] + 2 * (k - 1)
				break
		print(n)


def f(n):
	for i in range(2, int(n ** (1 / 2)) + 1):
		if n % i == 0:
			return i
	return n
for i in range(int(input())):
	[n, k] = input().split(' ')
	n = int(n)
	k = int(k)
	n = n + f(n) + 2 * k - 2
	print(n)


def Prime_Seave(n, arr):
	ans = []
	arr[0] = False
	i = 4
	while i < n + 1:
		arr[i - 1] = False
		i += 2
	i = 3
	while i * i < n + 1:
		for k in range(i * i, n + 1, 2 * i):
			arr[k - 1] = False
		i += 2
	i = 1
	while i < n:
		if arr[i]:
			ans.append(i + 1)
		i += 1
	return ans
primes = Prime_Seave(10 ** 6, [True] * 10 ** 6)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
		continue
	v = 0
	fl = False
	while k:
		if n % 2 == 0:
			fl = True
			print(n + 2 * k)
			break
		for i in primes:
			if n % i == 0:
				n += i
				break
		k -= 1
	if not fl:
		print(n)


def factorize(n):
	sieve = [True] * (n + 1)
	for x in range(2, int(len(sieve) ** 0.5) + 1):
		if sieve[x]:
			for i in range(x + x, len(sieve), x):
				sieve[i] = False
	lowerPrimes = [i for i in range(2, len(sieve)) if sieve[i] and n % i == 0]
	return lowerPrimes
numcases = int(input())
for i in range(numcases):
	(n, k) = map(int, input().split())
	if n & 1:
		n = n + min(factorize(n)) + 2 * (k - 1)
	else:
		n = n + 2 * k
	print(n)


n6_add1 = lambda n: n * 6 + 1
n6_sub1 = lambda n: n * 6 - 1

def factors(n, k):
	if n % 2 == 0:
		n += 2 * k
	elif n % 3 == 0:
		n += 3 + 2 * (k - 1)
	else:
		cutoff = int(n ** (1 / 2))
		i = 1
		i_add1 = 7
		i_sub1 = 5
		while i_sub1 <= cutoff:
			if n % i_sub1 == 0:
				n += i_sub1 + 2 * (k - 1)
				break
			elif n % i_add1 == 0:
				n += i_add1 + 2 * (k - 1)
				break
			i += 1
			i_sub1 = n6_sub1(i)
			i_add1 = n6_add1(i)
		else:
			n += n + 2 * (k - 1)
	return n
for _ in range(int(input())):
	nk = input().split(' ')
	(n, k) = (int(nk[0]), int(nk[1]))
	print(factors(n, k))


import os
import sys
from io import BytesIO, IOBase
from math import sqrt

def solution(n, k):
	if n & 1 == 0:
		write(n + 2 * k)
	else:
		factor = -1
		for i in range(1, int(sqrt(n)) + 1):
			if n % i == 0 and i > 1:
				factor = i
				break
		if factor == -1:
			factor = n
		res = n + factor
		res += 2 * (k - 1)
		write(res)

def main():
	for _ in range(r_int()):
		(n, k) = r_array()
		solution(n, k)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


from math import sqrt
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		f = 0
		for i in range(3, int(sqrt(n)) + 1, 2):
			if n % i == 0:
				n += i
				f = 1
				break
		if f:
			print(n + (k - 1) * 2)
		else:
			print(2 * n + (k - 1) * 2)


T = int(input())
for t in range(0, T):
	[n, k] = list(map(int, input().strip().split()))
	p = 0
	for i in range(0, k):
		if n % 2 == 0:
			print(n + 2 * (k - p))
			break
		else:
			for i in range(2, n + 1):
				if n % i == 0:
					f = i
					break
			n = n + f
			p += 1
			if p == k:
				print(n)


import math
t = int(input())

def div(n):
	ul = math.ceil(math.sqrt(n))
	if n % 2 == 0:
		return 2
	else:
		for i in range(3, ul + 1, 2):
			if n % i == 0:
				return i
				break
	return n
for i in range(0, t):
	(n, k) = list(map(int, input().split()))
	n = n + div(n) + 2 * max(0, k - 1)
	print(n)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def SieveOfEratosthenes(n):
	ans = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			ans.append(p)
	return ans
primes = set(SieveOfEratosthenes(int(1000000.0)))
ls = [2, 3, 5]
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n in primes:
		n += n
		k -= 1
	for i in primes:
		if n % i == 0 and k > 0:
			n += i
			k -= 1
			break
	if k > 0:
		n += 2 * k
	print(n)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	best = 0
	for i in range(2, n + 1):
		if n % i == 0:
			best = i
			break
	print(n + best + 2 * (k - 1))


cases = int(input())
for i in range(cases):
	l1 = input().split(' ')
	n = int(l1[0])
	k = int(l1[1])
	ans = 0
	if n % 2 == 0:
		ans = n + k * 2
		print(ans)
	else:
		factor = 0
		for j in range(3, n + 1):
			if n % j == 0:
				factor = j
				break
		ans = n + j + (k - 1) * 2
		print(ans)


t = int(input())

def solve(n, k):
	final = 0
	s = 2
	while n % s != 0:
		s += 1
	final += n + s + (k - 1) * 2
	return final
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	print(solve(n, k))


def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + make_divisors(n)[1] + 2 * (k - 1))


a = int(input())
for p in range(a):
	(n, k) = [int(x) for x in input().split()]
	x = 0
	if n % 2 == 0:
		print(n + k * 2)
	else:
		for i in range(k):
			if n % 2 == 0:
				print(n + (k - i) * 2)
				x = 1
				break
			for j in range(2, n + 1):
				if n % j == 0:
					n += j
					break
		if x == 0:
			print(n)


import math

def oaf(n, k):
	l = []
	if n % 2 == 0:
		n = n + 2 * k
	else:
		for i in range(1, int(math.sqrt(n) + 1)):
			if n % i == 0:
				l.append(i)
				l.append(int(n / i))
		p = set(l)
		q = list(p)
		q.sort()
		n = n + q[1]
		n = n + 2 * (k - 1)
	print(n)
	return
t = int(input())
for i in range(t):
	T = input()
	l = list(map(int, T.split()))
	oaf(l[0], l[1])


from math import gcd as g
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	x = 0
	for _ in range(2, n + 1):
		if n % _ == 0:
			x = _
			break
	print(n + x + (m - 1) * 2)


def check_divisors(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return i
	return n
t = int(input())
nk = [list(map(int, input().split())) for i in range(t)]
for i in range(t):
	(n, k) = nk[i]
	ans = n
	for j in range(k):
		c = check_divisors(ans)
		if c == 2:
			ans += (k - j) * 2
			break
		else:
			ans += c
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		j = 2
		while j * j <= n:
			if n % j == 0:
				break
			j += 1
		else:
			print(2 * n + 2 * (k - 1))
			continue
		print(n + j + 2 * (k - 1))


import io
import os
import sys
from atexit import register
import random
import math
import itertools
DEBUG = False
STRESSTEST = False
if not DEBUG:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
sys.stdout = io.BytesIO()
register(lambda : os.write(1, sys.stdout.getvalue()))
tokens = []
tokens_next = 0

def nextStr():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = input().split()
		tokens_next = 0
	tokens_next += 1
	if type(tokens[tokens_next - 1]) == str:
		return tokens[tokens_next - 1]
	return tokens[tokens_next - 1].decode()

def nextInt():
	return int(nextStr())

def nextIntArr(n):
	return [nextInt() for i in range(n)]

def print(*argv, end='\n'):
	for arg in argv:
		sys.stdout.write((str(arg) + ' ').encode())
	sys.stdout.write(end.encode())

def genTestCase():
	raise NotImplementedError

def bruteforce(n, k):
	for _ in range(k):
		n += next((i for i in range(2, n + 1) if n % i == 0))
	return n

def doStressTest():
	while True:
		curTest = genTestCase()
		mySoln = solve(curTest)
		bruteforceSoln = bruteforce(curTest)
		if mySoln != bruteforceSoln:
			print('### Found case ###')
			print(curTest)
			print(f'{mySoln} should have been: {bruteforceSoln}')
			return

def solve(n, k):

	def f(n):
		return next((i for i in range(2, int(n ** 0.5) + 10) if n % i == 0), n)
	while f(n) > 2:
		n += f(n)
		k -= 1
	return n + k * f(n)
if not DEBUG and STRESSTEST:
	raise Exception('Wrong flags!')
if STRESSTEST:
	doStressTest()
else:
	t = nextInt()
	for _ in range(t):
		n = nextInt()
		k = nextInt()
		print(solve(n, k))
sys.stdout.flush()


import math

def f(n, x):
	sum = val = n
	for _ in range(2, int(n / 2) + 1):
		if n % _ == 0:
			val = _
			break
	return sum + val + 2 * (x - 1)
imp = int(input())
for _ in range(imp):
	(n, x) = map(int, input().split())
	print(f(n, x))


def sd(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	for i in range(k):
		j = sd(n)
		if j == 2:
			n += 2 * (k - i)
			break
		else:
			n += j
	print(n)


n = int(input())
for k in range(n):
	(a, b) = map(int, input().split())
	a_1 = 0
	for i in range(2, a + 1):
		if a % i == 0:
			a_1 = a + i
			break
	if b == 1:
		print(a_1)
	else:
		for j in range(2, a_1 + 1):
			if a_1 % j == 0:
				min_div = j
				break
		print(a_1 + min_div * (b - 1))


from math import sqrt

def lcd(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	ld = lcd(n)
	print(n + ld + 2 * (k - 1))


import sys, math
l = [0 for i in range(10 ** 6 + 10)]

def calculate(n):
	if l[n] != 0:
		return l[n]
	else:
		for i in range(2, int(math.sqrt(n)) + 2):
			if n % i == 0:
				l[n] = i
				return i
		return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	for z in range(k):
		if n % 2 == 0:
			n += (k - z) * 2
			break
		else:
			n = n + calculate(n)
	print(n)


def isprime(n):
	c = 0
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			c += 1
		if c > 0:
			return False
	return True
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	elif isprime(n) == True:
		x = 2 * n + (k - 1) * 2
		print(x)
	else:
		p = 0
		for j in range(2, int(n ** 0.5) + 1):
			if n % j == 0:
				p = j
				break
		print(n + p + 2 * (k - 1))


import bisect
from math import pi
from collections import deque
from math import factorial
from math import log, ceil
from collections import defaultdict
from math import *
from sys import stdin, stdout
import itertools
import os
import sys
import threading
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import *
from fractions import Fraction
mod = int(pow(10, 9) + 7)

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li1():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d:
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d:
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = defaultdict(list)
	for i in range(n):
		(x, y) = mi()
		d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)

def SieveOfEratosthenes(n, isPrime):
	isPrime[0] = isPrime[1] = False
	for i in range(2, n):
		isPrime[i] = True
	p = 2
	while p * p <= n:
		if isPrime[p] == True:
			i = p * p
			while i <= n:
				isPrime[i] = False
				i += p
		p += 1
	return isPrime

def dijkstra(edges, f, t):
	g = defaultdict(list)
	for (l, r, c) in edges:
		g[l].append((c, r))
	(q, seen, mins) = ([(0, f, ())], set(), {f: 0})
	while q:
		(cost, v1, path) = heappop(q)
		if v1 not in seen:
			seen.add(v1)
			path = (v1, path)
			if v1 == t:
				return (cost, path)
			for (c, v2) in g.get(v1, ()):
				if v2 in seen:
					continue
				prev = mins.get(v2, None)
				next = cost + c
				if prev is None or next < prev:
					mins[v2] = next
					heappush(q, (next, v2, path))
	return float('inf')

def binsearch(a, l, r, x):
	while l <= r:
		mid = l + (r - 1) // 2
		if a[mid]:
			return mid
		elif a[mid] > x:
			l = mid - 1
		else:
			r = mid + 1
	return -1

def readTree(n):
	adj = [set() for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		adj[u - 1].add(v - 1)
		adj[v - 1].add(u - 1)
	return adj

def treeOrderByDepth(n, adj, root=0):
	parent = [-2] + [-1] * (n - 1)
	ordered = []
	q = deque()
	q.append(root)
	depth = [0] * n
	while q:
		c = q.popleft()
		ordered.append(c)
		for a in adj[c]:
			if parent[a] == -1:
				parent[a] = c
				depth[a] = depth[c] + 1
				q.append(a)
	return (ordered, parent, depth)

def sub_lists(l):
	out = []
	d = defaultdict(int)
	e = defaultdict(int)
	for i in l:
		d[i] += 1
		e[i] = 0
	c = 0
	for i in range(len(l)):
		x = l[i]
		for j in range(i + 1, len(l)):
			x += l[j]
			if x in l and e[x] < d[x]:
				c += 1
				e[x] += 1
	return c

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = ii()
for _ in range(t):
	(n, k) = mi()
	x = smallestDivisor(n)
	x += n
	print(x + 2 * (k - 1))


t = int(input())
while t > 0:
	(n, k) = [int(ele) for ele in input().split()]
	for i in range(2, n + 1):
		if n % i == 0:
			break
	n += i
	k -= 1
	n += 2 * k
	print(n)
	t -= 1


def f(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + f(n) + 2 * (k - 1))


def find(n):
	ans = None
	for i in range(2, int(n ** 5)):
		if n % i == 0:
			ans = i
			return i
	if not ans:
		return n

def solve(n, k):
	a = find(n)
	n += a
	n += (k - 1) * 2
	return n
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	print(solve(n, k))


def isprime(num):
	if num > 1:
		for i in range(2, num // 2):
			if num % i == 0:
				return False
				break
			else:
				return True
	else:
		return False
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a % 2 == 0:
		print(a + 2 * b)
	else:
		for i in range(2, a // 2):
			if a % i == 0:
				print(i + a + 2 * (b - 1))
				break
		else:
			print(2 * a + 2 * (b - 1))


def solve(n, k):
	if n % 2 == 0:
		return n + 2 * k
	else:
		d = 0
		for j in range(3, n):
			if n % j == 0:
				d = j
				break
		if d == 0:
			return 2 * n + 2 * (k - 1)
		else:
			return n + d + 2 * (k - 1)
t = int(input())
for i in range(t):
	(n, k) = tuple(map(int, input().split()))
	print(solve(n, k))


import math
n = int(input())
i = 0
while i < n:
	(x, y) = map(int, input().split(' '))
	if x % 2 == 0:
		print(x + 2 * y)
	else:
		for z in range(3, x + 1):
			if x % z == 0:
				x = x + z
				x = x + 2 * (y - 1)
				break
		print(x)
	i = i + 1


import math
t = int(input())
while t:
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		a = 0
		for i in range(3, int(math.sqrt(n)) + 1):
			if n % i == 0:
				a = i
				break
		if a == 0:
			n += n
			print(n + 2 * (k - 1))
		else:
			n += a
			print(n + 2 * (k - 1))
	t -= 1


import math
testCases = int(input())
for _ in range(testCases):
	(n, k) = map(int, input().split())
	check = math.ceil(math.sqrt(n))
	while k > 0:
		function = n
		for value in range(2, check + 1):
			if n % value == 0:
				function = value
				break
		if function == 2:
			n += 2 * k
			break
		n = n + function
		k -= 1
	print(n)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = 0
	if a % 2 != 0:
		for j in range(2, int(math.sqrt(a)) + 1):
			if a % j == 0:
				a += j
				c += 1
				break
		if c == 0:
			a += a
		b -= 1
	print(a + b * 2)


import math
t = int(input())
for z in range(t):
	(n, k) = map(int, input().rstrip().split())
	ans = n
	i = 0
	while i < k:
		fact = 1
		j = 2
		while j < round(math.sqrt(ans)) + 1:
			if ans % j == 0:
				fact = j
				ans = ans + fact
				break
			j += 1
		if fact == 1:
			fact = ans
			ans = ans + fact
		i += 1
		if ans % 2 == 0:
			break
	print(ans + (k - i) * 2)


T = int(input())
for _ in range(T):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	flag = 0
	for i in range(2, n + 1):
		if n % i == 0:
			flag = i
			break
	print(n + flag + 2 * (k - 1))


import sys
input = sys.stdin.readline
t = int(input())
nk = [list(map(int, input().split())) for _ in range(t)]
for (n, k) in nk:
	if not n % 2:
		print(n + 2 * k)
	else:
		for i in range(3, n + 1):
			if n % i:
				continue
			else:
				print(n + i + 2 * (k - 1))
				break


import math
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		s = 0
		is_p = True
		for i in range(3, int(math.sqrt(n)) + 1):
			if n % i == 0:
				s = i
				is_p = False
				break
		if is_p:
			print(2 * n + 2 * (k - 1))
		else:
			s = n + s
			print(s + 2 * (k - 1))


import math

def rem(n):
	for i in range(3, int(math.sqrt(n)) + 3):
		if n % i == 0:
			return i
	return n
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		s = rem(n)
		n += s
		print(n + 2 * (k - 1))


from sys import stdout, stdin
import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def div(x):
	i = 1
	mi = 1000000000
	while i * i <= x:
		if x % i == 0:
			if x // i == i:
				if i < mi and i != 1:
					mi = i
			else:
				if i < mi and i != 1:
					mi = i
				if n // i < mi and n // i != 1:
					mi = n // i
		i += 1
	return mi
for t in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 0
	if n % 2 == 0:
		ans = n + 2 * k
	else:
		ans = n + div(n) + 2 * (k - 1)
	stdout.write(str(ans) + '\n')


for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a % 2 == 0:
		print(a + b * 2)
	else:
		ans = a
		for j in range(2, a // 2):
			if a % j == 0:
				ans = j
				break
		print(a + ans + (b - 1) * 2)


def fun(x):
	if x in d:
		return d[x]
	else:
		for i in range(2, int(x ** 0.5) + 1):
			if x % i == 0:
				d[x] = i
				return i
		d[x] = x
		return x
t = int(input())
d = dict()
while t:
	(n, k) = list(map(int, input().split()))
	n += fun(n)
	n += 2 * (k - 1)
	print(n)
	t -= 1


import os, sys
from io import BytesIO, IOBase
from collections import Counter
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def sieve(n):
	i = 2
	p = [1 for i in range(n + 1)]
	z = 2
	while z * z <= n:
		if p[z] == 1:
			for i in range(z * z, n + 1, z):
				p[i] = 0
		z += 1
	primes = [2]
	for i in range(3, n + 1, 2):
		if p[i]:
			primes.append(i)
	return set(primes)
primes = sieve(10 ** 6)
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if x % 2 == 0:
		x = x + 2 * y
	elif x % 3 == 0:
		x = x + 3
		y = y - 1
		x = x + y * 2
	elif x % 5 == 0:
		x = x + 5
		y = y - 1
		x = x + y * 2
	elif x % 7 == 0:
		x = x + 7
		y = y - 1
		x = x + y * 2
	else:
		for t in primes:
			if x % t == 0:
				x = x + t
				y = y - 1
				x = x + 2 * y
				break
	print(x)


import sys
TEST = 0
if TEST == 1:
	input_file = open('inputA.txt', 'r')
	input_from_file = input_file.readlines()

def read_int():
	if TEST:
		return int(input_from_file.pop(0))
	else:
		return int(sys.stdin.readline())

def read_ints():
	if TEST:
		return list(map(int, input_from_file.pop(0).rstrip().split()))
	else:
		return list(map(int, sys.stdin.readline().split()))
t = read_int()

def f(n):
	mindel = n
	for i in range(2, n - 1, 1):
		if n % i == 0:
			mindel = i
			return mindel
	return mindel
for j in range(t):
	(n, k) = read_ints()
	cur_f = f(n)
	print(n + cur_f + 2 * (k - 1))


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math
import math
import time

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

def SieveOfEratosthenes(n):
	prime = [-1 for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == -1:
			for i in range(p * p, n + 1, p):
				prime[i] = p
		p += 1
	for i in range(2, n + 1):
		if prime[i] == -1:
			prime[i] = i
	return prime

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if val >= ll[mid][0] and val <= ll[mid][1]:
			return mid
		elif val < ll[mid][0]:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def deci(n):
	s = ''
	while n != 0:
		if n % 2 == 0:
			n = n // 2
			s = '0' + s
		else:
			n = n // 2
			s = '1' + s
	return s

def diff(s1, s2):
	if len(s1) < len(s2):
		v = len(s1)
		while v != len(s2):
			s1 = '0' + s1
			v = v + 1
	else:
		v = len(s2)
		while v != len(s1):
			s2 = '0' + s2
			v = v + 1
	c = 0
	for i in range(len(s1)):
		if s1[i:i + 1] != s2[i:i + 1]:
			c = c + 1
	return c
from sys import stdin, stdout

def fac(a, b):
	v = a
	while a != b:
		v *= a - 1
		a = a - 1
	return v

def bino(l, r, n):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		val1 = math.log(n / mid + 1, 2)
		val2 = int(val1)
		if val1 == val2:
			return val1
		elif val1 < 1.0:
			return bino(l, mid - 1, n)
		else:
			return bino(mid + 1, r, n)

def binary(l, r, val, ans):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		v = val ** 5 - mid ** 5
		print(v)
		if v == ans:
			print('HOHOHOH')
			return mid
		elif v < ans:
			return binary(mid + 1, r, val, ans)
		else:
			return binary(l, mid - 1, val, ans)

def check(n):
	v = 1
	while n != 0:
		if n % 10 == 0 or n % 10 == 1:
			n = n // 10
		else:
			v = 0
			break
	return v

def stairs(n, m, val, c, l):
	if val > n:
		return 100000
	elif val == n:
		if l[val] != -1:
			return l[val]
		elif c % m == 0:
			l[val] = c
			return l[val]
		else:
			l[val] = 100000
			return l[val]
	else:
		l[val] = min(stairs(n, m, val + 1, c + 1, l), stairs(n, m, val + 2, c + 1, l))
		return l[val]

def fact(n):
	if n == 0 or n == 1:
		return 1
	else:
		return n * fact(n - 1)

def some(n):
	s = 0
	while n != 0:
		s += fact(n % 10)
		n //= 10
	return s

def bin(l, r, val, ll):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if ll[mid] == val:
			return mid
		elif ll[mid] > val:
			return bin(l, mid - 1, val, ll)
		else:
			return bin(mid + 1, r, val, ll)

def fn(n):
	c = -1
	for i in range(2, int(sqrt(n)) + 1):
		if n % 2 == 0:
			c = i
			break
	if c == -1:
		c = n
	return c
l = SieveOfEratosthenes(1000000)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split(' '))
	val = 0
	for j in range(2, n + 1):
		if n % j == 0:
			val = j
			break
	print(n + val + (k - 1) * 2)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().strip().split()))
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		for i in range(3, n + 1):
			if n % i == 0:
				print(n + i + (k - 1) * 2)
				break


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	x = 2
	while x * x <= n:
		if n % x == 0:
			break
		x += 1
	else:
		x = n
	res = n + x + (k - 1) * 2
	print(res)


def main(n, k):
	if not n % 2:
		return k * 2 + n
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if not n % i:
				return n + i + (k - 1) * 2
		return n + n + (k - 1) * 2
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	print(main(n, k))


def solve():
	(n, k) = map(int, input().split())
	ans = True
	for i in range(2, int(n ** 0.5 + 1)):
		if n % i == 0:
			res = i
			ans = False
			break
	if ans == True:
		print(n + n + (k - 1) * 2)
	else:
		print(2 * (k - 1) + n + res)
test = int(input())
for _ in range(test):
	solve()


def lcm(num):
	for divisor in range(2, num + 1):
		if num % divisor == 0:
			return divisor
for _ in range(int(input())):
	(n, k) = (int(x) for x in input().split())
	if n % 2 == 0:
		print(lcm(n) * k + n)
	else:
		n = n + lcm(n)
		print(lcm(n) * (k - 1) + n)


def main():
	(n, k) = map(int, input().split())
	nm = 0
	if n % 2 != 0:
		for i in range(2, n + 1):
			if n % i == 0:
				nm = i
				break
		n += nm
		k -= 1
		n += k * 2
		print(n)
	else:
		print(n + k * 2)
t = int(input())
for i in range(t):
	main()


def smallest(n):
	for i in range(3, n, 2):
		if n % i == 0:
			return i
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + smallest(n) + 2 * (k - 1))


def findFactor(n):
	for i in range(3, n // 2 + 1, 2):
		if n % i == 0:
			return i
	return n

def solve():
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		f = findFactor(n)
		ans = f + n
		print(ans + (k - 1) * 2)
for _ in range(int(input())):
	solve()


def f(s):
	if s % 2 == 0:
		return 2
	for i in range(3, s + 1, 2):
		if s % i == 0:
			return i
			break
for t in range(int(input())):
	(n, k) = map(int, input().split())
	s = n + f(n) + 2 * (k - 1)
	print(s)


t = int(input())
ls = []
for i in range(t):
	(n, k) = map(int, input().split())
	ans = n
	if k == 1:
		for j in range(2, n + 1):
			if n % j == 0:
				ans += j
				n += j
				break
	else:
		for x in range(2):
			for j in range(2, n + 1):
				if n % j == 0:
					ans += j
					n += j
					break
		ans += j * (k - 2)
	ls.append(ans)
for y in range(t):
	print(ls[y])


def isPrime(n):
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if isPrime(n) and k == 1:
		print(n * 2)
	elif isPrime(n) and k > 1:
		ab = (k - 1) * 2
		print(n * 2 + ab)
	else:
		for x in range(2, n):
			if n % x == 0:
				c = x
				break
		ab = (k - 1) * 2
		print(n + c + ab)


import math
t = int(input())
while t:
	t -= 1
	i = input().split()
	n = int(i[0])
	k = int(i[1])
	if n % 2 == 0:
		print(n + 2 * k)
		continue
	z = False
	for i in range(2, int(math.sqrt(n) + 1)):
		if n % i == 0:
			n += i
			z = True
			break
	if z == False:
		n += n
	print(n + 2 * (k - 1))


for j in range(int(input())):
	(n, k) = map(int, input().split())
	for i in range(2, n + 1):
		if n % i == 0:
			break
	print(n + i + (k - 1) * 2)


import math
for t in range(0, int(input())):
	(n, k) = map(int, input().split())
	num = n
	flag = 0
	if num % 2 == 0:
		num = num + k * 2
		print(num)
		continue
	else:
		for i in range(3, int(math.sqrt(num) + 2), 2):
			if num % i == 0:
				num = num + i
				flag = 1
				break
		if flag == 0:
			num = num + num
		num = num + (k - 1) * 2
		print(num)


import math
t = int(input())
for tt in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		p = 0
		for i in range(2, n + 1):
			if n % i == 0:
				p = i
				break
		print(n + p + 2 * (k - 1))


def find(n):
	if n % 2 == 0:
		return 2
	for i in range(3, n + 1, 2):
		if n % i == 0:
			return i

def solve(n, m):
	for i in range(m):
		temp = find(n)
		n += temp
		if n % 2 == 0:
			n += (m - i - 1) * 2
			break
	print(n)
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	solve(n, k)


def for_odd(n):
	for i in range(3, n + 1):
		if n % i == 0:
			return i
for test in range(int(input())):
	(n, k) = map(int, input().split(' '))
	if n & 1:
		n += for_odd(n)
		print(n + 2 * (k - 1))
	else:
		print(n + 2 * k)


def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
		continue
	else:
		for i in range(k):
			if smallestDivisor(n) == 2:
				n = n + (k - i) * 2
				break
			else:
				n += smallestDivisor(n)
		print(n)


import sys

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
from math import *
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())
t = fi()
while t > 0:
	t -= 1
	(n, k) = mi()
	if n % 2 == 0:
		print(n + k * 2)
	else:
		d = -1
		for i in range(2, int(sqrt(n)) + 1):
			if n % i == 0:
				d = i
				break
		if d == -1:
			d = n
		print(n + d + (k - 1) * 2)


def smallest_divisor(n):
	i = 2
	while i * i <= n:
		if n % i == 0:
			return i
		i = i + 1
	return n

def solve(n, k):
	if n % 2 == 0:
		return n + 2 * k
	else:
		a = smallest_divisor(n)
		return n + a + (k - 1) * 2
t = 1
t = int(input())
while t > 0:
	(n, k) = [int(x) for x in input().split()]
	ans = solve(n, k)
	print(ans)
	t -= 1


def printDivisors(n):
	x = []
	i = 2
	while i <= n // 2:
		if n % i == 0:
			x.append(i)
			break
		i += 1
	if len(x) == 0:
		return n
	return x[0]
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % 2 == 0:
		print(a + 2 * b)
	else:
		(n, k) = (a, b)
		print(n + 2 * (k - 1) + printDivisors(n))


def f(n):
	i = 2
	while i * i <= n:
		if n % i == 0:
			return i
		else:
			i += 1
	return n
t = int(input())
for case in range(t):
	(n, k) = [int(x) for x in input().split(' ')]
	print(n + f(n) + 2 * (k - 1))


t = int(input())
nk = [list(map(int, input().split())) for _ in range(t)]

def primes(x):
	is_prime = [True] * (x + 1)
	is_prime[0] = False
	is_prime[1] = False
	for i in range(2, int(x ** 0.5) + 1):
		if not is_prime[i]:
			continue
		for j in range(i * 2, x + 1, i):
			is_prime[j] = False
	return [i for i in range(x + 1) if is_prime[i]]
prime_list = primes(10 ** 6)
for (n, k) in nk:
	if n % 2 == 1:
		for y in prime_list:
			if n % y == 0:
				fn = y
				break
		k -= 1
		n += fn
	if k > 0:
		n += 2 * k
	print(n)


def is_prime(n):
	if n == 1:
		return False
	i = 2
	while i * i <= n:
		if n % i == 0:
			return 0
		i += 1
	return 1
try:
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		tem = is_prime(n)
		ans = 0
		if tem:
			ans = 2 * n + (k - 1) * 2
		else:
			for i in range(2, n // 2 + 1):
				if n % i == 0:
					x = i
					break
			ans = n + x + (k - 1) * 2
		print(ans)
except:
	pass


import math
t = int(input())
for _ in range(0, t):
	(n, k) = list(map(int, input().split()))
	f = -1
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			f = i
			break
	if f == -1:
		f = n
	n += f
	k -= 1
	n += 2 * k
	print(n)


def div(n):
	i = 1
	k = []
	c = 0
	while i <= n:
		if n % i == 0:
			k.append(i)
			c += 1
		i = i + 1
		if c == 2:
			break
	if k == []:
		return 0
	else:
		return k[1]
t = int(input())
while t > 0:
	t -= 1
	(n, m) = list(map(int, input().split()))
	p = 0
	sum = 0
	nn = n
	sum = nn + div(nn)
	if n % 2 == 0:
		sum = nn + 2 * m
	else:
		sum = sum + 2 * (m - 1)
	print(sum)


import sys
t = int(input())
while t:
	(n, k) = map(int, sys.stdin.readline().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		for i in range(3, n + 1, 2):
			if n % i == 0:
				ans = i
				break
		ans += n
		print(ans + 2 * (k - 1))
	t -= 1


n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split()))
	prime = 1
	m = a
	for j in range(2, 1010):
		if a % j == 0:
			m = j
			break
		if j > a ** 0.5 + 3 * a:
			break
	if a % 2 == 0:
		print(a + 2 * b)
	else:
		print(a + m + (b - 1) * 2)


from math import sqrt
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		s = set({n})
		x = int(sqrt(n)) + 1
		for i in range(2, x):
			if n % i == 0:
				s.add(i)
				s.add(n // i)
		n += min(s)
		print(n + 2 * (k - 1))


for t in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		for g in range(2, n + 1):
			if n % g == 0:
				print(n + g + (k - 1) * 2)
				break


import math

def findlist(yy):
	number = yy
	ilk = []
	for q in range(2, number + 1):
		ilk.append(q)
	q = 2
	while q <= int(math.sqrt(number)):
		if q in ilk:
			for r in range(q * 2, number + 1, q):
				if r in ilk:
					ilk.remove(r)
		q = q + 1
	return ilk

def findsolution(number):
	sonuc = number
	if number % 2 == 0:
		sonuc = 2
	elif number % 3 == 0:
		sonuc = 3
	elif number % 5 == 0:
		sonuc = 5
	elif number % 7 == 0:
		sonuc = 7
	elif number % 11 == 0:
		sonuc = 11
	elif number % 13 == 0:
		sonuc = 13
	elif number % 17 == 0:
		sonuc = 17
	elif number % 19 == 0:
		sonuc = 19
	elif number % 23 == 0:
		sonuc = 23
	else:
		numb = int(math.sqrt(number))
		listx = findlist(numb)
		listx = listx[8:]
		for i in listx:
			i = int(i)
			if number % i == 0:
				sonuc = i
				break
	return sonuc
for i in range(0, int(input())):
	x = input().split()
	n = int(x[0])
	k = int(x[1])
	if n % 2 == 0:
		ekle = 2
		n += k * 2
	else:
		son = findsolution(n)
		n = n + son + (k - 1) * 2
	print(n)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		f = 0
		d = 2
		while d < n // 2:
			if n % d == 0:
				f = 1
				break
			d += 1
		if f == 0:
			d = n
		print(n + d + 2 * (k - 1))


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().rstrip().split()))
	c = -1
	for i in range(2, n + 1):
		if n % i == 0:
			c = i
			break
	ans = n + c + (k - 1) * 2
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = False
	b = n
	for j in range(2, int(n ** 0.5) + 1):
		if n % j == 0:
			b = j
			a = True
			break
	if a == False:
		if k == 1:
			print(2 * n)
		else:
			print(2 * n + 2 * (k - 1))
	elif k == 1:
		print(n + b)
	else:
		print(n + b + 2 * (k - 1))


from sys import stdin, stdout
input = lambda : stdin.readline().strip()
fast_print = stdout.write
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	for i in range(2, n + 1):
		if n % i == 0:
			break
	fast_print(str(n + i + 2 * (k - 1)) + '\n')


t = int(input())
inp = lambda : map(int, input().split())
import math

def f_n(n):
	i = 2
	flag = 0
	for i in range(2, int(math.ceil(math.sqrt(n))) + 1):
		if n % i == 0:
			flag = 1
			break
	if flag == 1:
		x = i
	else:
		x = n
	return x
for _ in range(t):
	(n, k) = inp()
	if n % 2 == 0:
		n += 2 * k
	else:
		n += f_n(n) + (k - 1) * 2
	print(n)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	f = 2
	found = False
	while f * f <= n:
		if n % f == 0:
			found = True
			break
		f += 1
	if not found:
		f = n
	print(n + f + 2 * (k - 1))


import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
t = int(input())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	if n % 2 == 0:
		print(n + k + k)
	else:
		val = -1
		for i in range(3, 1001):
			if n % i == 0:
				val = i
				break
		if val == -1:
			val = n
		print(n + 2 * (k - 1) + val)


import math
import atexit
import io
import sys
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def array_to_string(a):
	s = ''
	for i in a:
		s += str(i) + ' '
	return s[0:len(s) - 1]

def isPrime(n):
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return 0
	return 1

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)
t = int(input())
while t > 0:
	t = t - 1
	(n, k) = map(int, input().split())
	if isPrime(n):
		n = n + n
		k -= 1
		n += k * 2
	elif n % 2 != 0:
		div = 2
		while div > 0:
			if n % div == 0:
				break
			div += 1
		n += div
		n += (k - 1) * 2
	else:
		n += 2 * k
	print(n)


import math
t = int(input())

def low_fac(n):
	max_iter = int(math.sqrt(n))
	for i in range(2, max_iter + 1):
		if n % i == 0:
			return i
	return n
for i in range(0, t):
	(n, k) = input().strip().split()
	(n, k) = (int(n), int(k))
	print(n + low_fac(n) + 2 * (k - 1))


def SmallestDivisor(x):
	for i in range(2, x + 1):
		if x % i == 0:
			return i

def OracandFactors(n, k):
	if k == 1:
		return n + SmallestDivisor(n)
	n += SmallestDivisor(n)
	return n + 2 * (k - 1)
Lista = []
total = int(input())
for i in range(total):
	All = [int(i) for i in input().split()]
	Lista.append(All)
for j in Lista:
	print(OracandFactors(j[0], j[1]))


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys

def factorize(n):
	f = []
	p = 2
	while p ** 2 <= n:
		while n % p == 0:
			n = n // p
			f.append(p)
		p += 1
	if n != 1:
		f.append(n)
	return f

def solve(n, k):
	if n % 2 == 0:
		return n + k * 2
	f = factorize(n)[0]
	if k == 1:
		return n + f
	return solve(n + f, k - 1)

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		ans = solve(n, k)
		sys.stdout.write(str(ans) + '\n')
main()


import math
t = int(input())
for i in range(t):
	(n, k) = [int(n) for n in input().split()]
	div = 0
	if n % 2 == 0:
		n = n + 2
	else:
		for j in range(3, int(math.sqrt(n)) + 1, 2):
			if n % j == 0:
				div = j
				break
			else:
				continue
		if div == 0:
			div = n
		n = n + div
	k = k - 1
	if k > 0:
		n = n + 2 * k
	print(n)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k == 1:
		if n % 2 == 0:
			print(n + 2)
		else:
			for i in range(3, n + 1):
				if n % i == 0:
					print(n + i)
					break
	elif n % 2 == 0:
		print(n + 2 * k)
	else:
		for i in range(3, n + 1):
			if n % i == 0:
				ans = i
				break
		print(n + ans + (k - 1) * 2)


for test in range(int(input())):
	arr = list(map(int, input().split()))
	div = 0
	for i in range(2, arr[0] + 1):
		if arr[0] % i == 0:
			div = i
			break
	print(arr[0] + div + 2 * (arr[1] - 1))


def fn(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return i
	return n

def answer(n, k):
	n = fn(n) + n
	return n + 2 * (k - 1)
testCount = int(input())
for _ in range(testCount):
	(n, k) = map(int, input().split())
	print(answer(n, k))


from math import sqrt
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	flag = 0
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			n += i
			flag = 1
			break
	if flag == 0:
		n += n
	print(n + 2 * (m - 1))


x = int(input())
for i in range(x):
	(n, k) = map(int, input().split())
	c = 0
	for i in range(2, n + 1):
		if n % i == 0:
			n += i
			break
	print(n + (k - 1) * 2)


def div(i):
	j = 3
	while i % j != 0:
		j += 2
	return j
for x in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		n = n + k * 2
	else:
		c = div(n)
		n = n + c + (k - 1) * 2
	print(n)


def inlt():
	return list(map(int, input().split()))

def minDiv(num):
	for i in range(2, int(num / 2)):
		if num % i == 0:
			return i
	return num
t = int(input())
res = []
for i in range(t):
	[n, k] = inlt()
	for j in range(k):
		if n % 2 == 0:
			n = (k - j) * 2 + n
			break
		n = minDiv(n) + n
	res.append(n)
for i in range(t):
	print(res[i])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	d = 2
	while n % d != 0:
		d += 1
	n = n + d
	n = n + (k - 1) * 2
	print(n)


import sys

def f(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
t = int(input())
for tc in range(t):
	(n, k) = map(int, input().split())
	n += f(n)
	n += (k - 1) * 2
	print(n)


import math

def divisor(n):
	divisors = []
	divisors.append(n)
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			divisors.insert(0, i)
			break
	return divisors[0]
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		ans = n + 2 * (k - 1) + divisor(n)
		print(ans)


import math
t = int(input())
ans = []
for i in range(t):
	(n, k) = [int(i) for i in input().split()]
	if n % 2 == 0:
		n = n + 2 * k
	else:
		for i in range(3, n + 1, 2):
			if n % i == 0:
				n = n + i
				break
		k -= 1
		n = n + 2 * k
	ans.append(n)
for i in ans:
	print(i)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n
	flag = False
	for i in range(2, max(3, int(n ** 0.5) + 2)):
		if n % i == 0:
			ans = i
			break
	if n % 2 != 0:
		print(n + ans + (k - 1) * 2)
	else:
		print(n + k * 2)


def isprime(num):
	i = 2
	while i * i <= num:
		if num % i == 0:
			return [False, i]
		i += 1
	return [True]
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	x = isprime(n)
	if x[0] == False and x[1] % 2 == 0:
		print(n + k * x[1])
	else:
		flag = 0
		while k:
			x = isprime(n)
			if x[0] == False:
				if x[1] % 2 == 0:
					flag = 1
					print(n + k * x[1])
					break
				else:
					n += x[1]
			else:
				n = 2 * n
			k -= 1
		if flag == 0:
			print(n)


def main():
	from math import sqrt
	t = 1
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		if n % 2 == 0:
			print(n + k * 2)
		else:
			for i in range(3, n + 1):
				if n % i == 0:
					print(n + i + (k - 1) * 2)
					break
	return

def __starting_point():
	main()
__starting_point()


def f(n, k):
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		flag = 0
		v = 0
		for j in range(2, int(n ** (1 / 2)) + 1):
			if n % j == 0:
				flag = 1
				v = j
				break
		if flag == 0:
			n = 2 * n
		print(n + v + 2 * (k - 1))
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	f(n, k)


def div(num):
	for i in range(2, num // 2):
		if num % i == 0:
			return i
	return num
query = int(input())
for _ in range(query):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		n += k * 2
	else:
		n += div(n)
		n += (k - 1) * 2
	print(n)


def f(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
	else:
		return n
x = int(input())
for i in range(x):
	(n, k) = map(int, input().split())
	m = 0
	n = f(n) + n
	n = n + 2 * (k - 1)
	print(n)


import math
for w in range(int(input())):
	(x, y) = list(map(int, input().split()))
	if x % 2 == 0:
		print(x + y * 2)
	else:
		cont = 0
		for i in range(x // 2):
			if x % (i + 2) == 0:
				cont += i + 2
				break
		if cont == 0:
			cont = x
		y -= 1
		x += cont + y * 2
		print(x)


import math
found = False
t = int(input())
for a in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		n = n + k * 2
		print(n)
		continue
	else:
		found = False
		for x in range(2, int(math.sqrt(n)) + 2):
			if n / x % 1 == 0 and found == False:
				n += x
				found = True
		if found == True:
			n = n + k * 2 - 2
		else:
			n = n + n + k * 2 - 2
	print(n)


import math as mt
MAXN = int(pow(10, 6)) + 1
spf = [0] * MAXN

def sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, int(MAXN)):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
sieve()
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	fn = spf[n]
	if n % 2 == 0:
		n = n + k * 2
	else:
		n += spf[n]
		k -= 1
		n += 2 * k
	print(n)


def smallDiv(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	if not n % 2:
		print(n + 2 * k)
	else:
		x = n + smallDiv(n)
		i = 1
		while i <= k:
			if x % 2 == 0:
				print(x + 2 * (k - i))
				break
			else:
				i += 1
				x = x + smallDiv(x)


import math
for i in range(int(input())):
	(n, k) = map(int, input().split())
	m = n
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		for j in range(3, int(math.sqrt(n)) + 1):
			if n % j == 0:
				m = j
				break
		print(n + m + 2 * (k - 1))


from sys import stdin

def prime_factors(n):
	ret = []
	apnd = ret.append
	while n >= 4:
		if n % 2:
			break
		else:
			n //= 2
			apnd(2)
	i = 3
	while n >= i * i:
		if n % i:
			i += 2
		else:
			n //= i
			apnd(i)
	apnd(n)
	return ret

def main():
	input = lambda : stdin.readline()[:-1]
	T = int(input())
	for _ in [0] * T:
		(N, K) = map(int, input().split())
		if N % 2:
			p = prime_factors(N)
			N += p[0]
			ans = 2 * (K - 1) + N
		else:
			ans = 2 * K + N
		print(ans)
main()


from math import *
t = int(input())
while t:
	t -= 1
	(n, k) = [int(x) for x in input().split()]
	p = n
	for x in range(2, int(sqrt(n) + 1)):
		if n % x == 0:
			p = x
			break
	s = n / p
	if s % 2 == 0:
		print(n + 2 * k)
	else:
		k -= 1
		print(n + p + 2 * k)


def main():

	def fact(n):
		i = 2
		while i < n // 2:
			if n % i == 0:
				return i
			i += 1
		return n

	def calc(n, k):
		if n % 2 == 0:
			return n + 2 * k
		else:
			v = fact(n)
			return n + v + 2 * (k - 1)
	t = int(input())
	while t > 0:
		(n, k) = list(map(int, input().split()))
		print(calc(n, k))
		t -= 1
main()


from collections import defaultdict, Counter
from math import ceil
import math

def divisorGenerator(n):
	large_divisors = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			yield i
			if i * i != n:
				large_divisors.append(n / i)
	for divisor in reversed(large_divisors):
		yield divisor
alph = 'abcdefghijklmnopqrstuvwxyz'
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	i = 0
	while i < k:
		gen = divisorGenerator(n)
		next(gen)
		add = int(next(gen))
		if add == 2:
			n += add * (k - i)
			break
		else:
			n += add
			i += 1
	print(n)


prime = [True for i in range(1000000 + 1)]

def s(n):
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1

def f(n):
	for i in range(2, 1000001):
		if prime[i] == True:
			if n % i == 0:
				return i
s(1000000)
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		i = 0
		while i < k:
			n += f(n)
			i += 1
			if n % 2 == 0:
				break
		print(n + 2 * (k - i))


t = int(input())

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for i in range(t):
	(n, k) = list(map(int, input().strip().split(' ')))
	print(n + smallestDivisor(n) + 2 * (k - 1))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	p = 0
	if n % 2 == 0:
		print(n + 2 * k)
		continue
	else:
		for i in range(n, 1, -1):
			if n % i == 0:
				p = i
		print(n + p + 2 * (k - 1))


def fact(n):
	if n == 1:
		return 1
	else:
		for i in range(2, n + 1):
			if n % i == 0:
				return i
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	r = k
	while k:
		if n % 2 == 0:
			n = n + k * 2
			break
		else:
			n = n + fact(n)
		k = k - 1
	print(n)


arr = []

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			arr.append(p)
SieveOfEratosthenes(10 ** 6)
for _ in range(int(input())):
	(N, k) = map(int, input().split())
	for i in arr:
		if N % i == 0:
			N += i
			break
	N += (k - 1) * 2
	print(N)


def f(n):
	answer = 1
	for i in range(2, n + 1):
		if n % i == 0:
			answer = i
			return answer
			break
t = int(input())
while t > 0:
	(n, k) = list(map(int, input().split()))
	add = f(n)
	if n % 2 == 0:
		n += 2 * k
	else:
		n = n + add + 2 * (k - 1)
	print(n)
	t -= 1


import math as mt
global spf
spf = [0] * 1000001

def spfc():
	global spf
	for i in range(2, 1000001):
		if spf[i] != 0:
			continue
		spf[i] = i
		for j in range(i * i, 1000001, i):
			if spf[j] == 0:
				spf[j] = i

def main():
	global spf
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		print(n + spf[n] + (k - 1) * 2)
spfc()
main()


from math import sqrt

def largest(n):
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return i
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
		continue
	print(n + largest(n) + 2 * (k - 1))


def enes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	m = []
	for p in range(2, n + 1):
		if prime[p]:
			m.append(p)
	return m
for t in range(int(input())):
	(n, k) = map(int, input().split())
	r = int(n ** (1 / 2) + 1)
	g = 0
	if n & 1 == 0:
		g = n + 2 * k
		print(g)
	else:
		h = enes(n)
		for i in range(len(h)):
			if n % h[i] == 0:
				s = n + h[i] + 2 * (k - 1)
				print(s)
				break


import sys, os

def f():
	args = list(map(int, input().split()))
	if len(args) > 1:
		return args
	return args[0]
if 'local' in os.environ:
	sys.stdin = open('./input.txt', 'r')

def get_qsa(file_name):
	(audio, size) = readfile(file_name)
	headers = {'Connection': 'keep-alive', 'Content-Length': str(size)}
	parameter = {'request_id': int(time.time() * 100), 'th': 1, 'tht': 'qf492_100fps', 'the': 1.0, 'thst': 'neural'}
	res = requests.post(f"http://{config['ip']}:{config['port']}", timeout=120, data=audio, headers=headers, params=parameter)
	res_json = res.json()
	if res_json['retmsg'] != 'success':
		raise Exception
	bin_str = res_json['th'][0]['feat']
	bin_data = base64.b64decode(bin_str)
	bin2qsa_siren(bin_data, file_name)

def solve():
	t = f()
	for i in range(t):
		(n, k) = f()
		for j in range(2, n + 1):
			if n % j == 0:
				l = j
				break
		n += l
		n += 2 * (k - 1)
		print(n)
solve()


t = int(input())
for a in range(t):
	(n, k) = list(map(int, input().split()))
	if n % 2 == 0:
		n += 2 * k
	else:
		for a in range(3, n + 1):
			if n % a == 0:
				n += a
				n += 2 * (k - 1)
				break
	print(n)


from sys import stdin
from math import gcd
inp = lambda : stdin.readline().strip()
primes = []

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p]:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			primes.append(p)
SieveOfEratosthenes(10 ** 6)
t = int(inp())
for _ in range(t):
	(n, k) = [int(x) for x in inp().split()]
	if n % 2:
		for j in primes:
			if n % j == 0:
				n += j
				break
		k -= 1
	n = n + 2 * k
	print(n)


def ans(n, k):
	p = k
	while p > 0:
		s = 0
		if n % 2 == 0:
			break
		for i in range(2, n + 1):
			if n % i == 0:
				s = i
				n += i
				break
		p -= 1
	n += 2 * p
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(ans(n, k))


T = int(input())
while T != 0:
	(n, k) = map(int, input().split())
	count = 2
	final_ans = n
	while k != 0:
		count = 2
		while count < n:
			if final_ans % count == 0:
				final_ans = final_ans + count
				break
			count += 1
		if count == n:
			final_ans = final_ans + n
		if count == 2:
			final_ans = final_ans + (k - 1) * 2
			break
		k -= 1
	print(final_ans)
	T -= 1


def solution():
	(n, k) = map(int, input().split())
	while n % 2 != 0:
		x = 0
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				x = i
				break
		if x == 0:
			x = n
		n += x
		k -= 1
	print(n + 2 * k)
for _ in range(int(input())):
	solution()


import math
import sys
from collections import defaultdict, Counter, deque, OrderedDict
import bisect
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]
from itertools import accumulate, groupby
import sys

def printDivisors(n):
	A = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				A.append(i)
			else:
				A.append(i)
				A.append(n // i)
		i = i + 1
	return A
for _ in range(int(input())):
	(n, k) = ilele()
	if n % 2 == 0:
		x = n + k * 2
		print(x)
	else:
		A = printDivisors(n)
		if 1 in A:
			A.remove(1)
		y = min(A)
		n = n + y
		print(n + 2 * (k - 1))


import math
t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	minn = 2
	while minn * minn <= n:
		if n % minn == 0:
			break
		minn += 1
	if minn * minn > n:
		minn = n
	n += minn
	n += (m - 1) * 2
	print(n)


def fun(n):
	for i in range(2, n + 1):
		if n % i == 0:
			break
	return i
for __ in range(int(input())):
	(n, k) = map(int, input().split())
	for i in range(2, n + 1):
		if n % i == 0:
			break
	if i == 2:
		c = n + i * k
		print(c)
	else:
		c = n + i
		k -= 1
		x = fun(c)
		if x == 2:
			c = c + 2 * k
			print(c)


t = int(input())
for i in range(t):
	nk = list(map(int, input().strip().split()))
	n = nk[0]
	k = nk[1]
	d = 2
	while n % d != 0:
		d += 1
	print(n + d + 2 * k - 2)


import math
number = int(input())

def smallestDiv(n):
	sD = 2
	found = False
	while sD < math.sqrt(n) + 1:
		if n % sD == 0:
			found = True
			break
		sD += 1
	if not found:
		sD = n
	return sD
for taskN in range(number):
	inputs = input()
	(n, k) = list(map(int, inputs.split(' ')))
	for i in range(k):
		if n % 2 == 0:
			n += (k - i) * 2
			break
		n += smallestDiv(n)
	print(n)


import math

def f(n):
	flag = 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return i
	return n
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + 2 * (k - 1) + f(n))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		f = True
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				f = False
				break
		print(2 * n + (k - 1) * 2 if f else n + i + (k - 1) * 2)


n = int(input())
for i in range(n):
	(t, k) = list(map(int, input().split()))
	while t % 2 == 1 and k > 0:
		flag = False
		for i in range(3, int(t ** 0.5) + 1):
			if t % i == 0:
				t += i
				flag = True
				break
		if not flag:
			t += t
		k -= 1
	t += 2 * k
	print(t)


import sys
input = sys.stdin.buffer.readline
t = int(input())
ans = []
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2:
		m = n
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				m = i
				break
		ans.append(n + m + 2 * (k - 1))
	else:
		ans.append(n + 2 * k)
print('\n'.join(map(str, ans)))


import math
import sys
input = sys.stdin.readline

def main():
	test = int(input())
	for _ in range(test):
		(n, k) = map(int, input().split())
		root = math.floor(math.sqrt(n)) + 1
		ans = n
		for div in range(2, root):
			if n % div == 0:
				ans += div
				break
		if ans == n:
			ans += n
		ans += 2 * (k - 1)
		print(ans)
main()


import math
t = int(input())
while t > 0:
	t = t - 1
	nk = input()
	n = int(nk.split()[0])
	k = int(nk.split()[1])
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		flag = False
		for i in range(2, int(math.sqrt(n) + 1)):
			if n % i == 0:
				n = n + i
				flag = True
				break
		if flag == False:
			n = 2 * n
		print(n + 2 * (k - 1))


def solve(n, k):
	if n % 2 == 0:
		return n + 2 * k
	else:
		flag = False
		for j in range(2, n):
			if n % j == 0:
				flag = True
				n = n + j
				return solve(n, k - 1)
		if flag == False:
			n = n + n
			return solve(n, k - 1)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print(solve(n, k))


from math import sqrt

def solve(N, K):
	temp1 = sqrt(N)
	temp2 = int(temp1)
	factors = [1]
	if temp1 == temp2:
		for i in range(2, temp2):
			if N % i == 0:
				factors.append(i)
				factors.append(N // i)
		factors.append(temp2)
	else:
		for i in range(2, temp2 + 1):
			if N % i == 0:
				factors.append(i)
				factors.append(N // i)
	factors.append(N)
	p = N + factors[1] + 2 * (K - 1)
	print(p)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		solve(n, k)


t = int(input())
for j in range(t):
	g = input().split()
	n = int(g[0])
	k = int(g[1])
	p = 0
	for i in range(2, n + 1):
		if n % i == 0:
			p = i
			break
	print(n + p + (k - 1) * 2)


t = int(input())
for test in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	s = 2
	while n % s != 0:
		s += 1
	ans = n + s + (k - 1) * 2
	print(ans)


from math import sqrt

def solve(n, k):
	if k == 0:
		return n
	if n % 2:
		smalDiv = None
		for i in range(2, int(sqrt(n)) + 2):
			if n % i == 0:
				smalDiv = i
				break
		if not smalDiv:
			smalDiv = n
		n += smalDiv
		if k == 1:
			return n
		else:
			return n + (k - 1) * 2
	else:
		return n + k * 2
t = int(input())
while t:
	t -= 1
	(n, k) = tuple(map(int, input().strip().split(' ')))
	print(solve(n, k))


t = int(input())
for i in range(t):
	d = list(map(int, input().split()))
	if d[0] % 2 == 0:
		print(d[0] + d[1] * 2)
	else:
		x = 0
		for i in range(d[0], 2, -1):
			if d[0] % i == 0:
				x = i
		print(d[0] + x + (d[1] - 1) * 2)


import math

def isPrime(x):
	for d in range(2, int(math.sqrt(x)) + 1):
		if x % d == 0:
			return False
	return True
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if isPrime(n):
		ans = n + n + (k - 1) * 2
	elif n % 2 == 0:
		ans = n + 2 * k
	else:
		factors = []
		for j in range(2, int(math.sqrt(n)) + 1):
			if n % j == 0:
				factors.append(j)
				if n // j != j:
					factors.append(n // j)
		if factors[0] % 2 != 0:
			ans = n + factors[0] + (k - 1) * 2
	print(ans)


def minDiv(n):
	if n <= 3:
		return n
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return i
	return n
t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	if n % 2 != 0:
		t = minDiv(n)
		print(n + t + (k - 1) * 2)
	else:
		print(n + 2 * k)


def g(p):
	if p % 2 == 0:
		return 2
	else:
		i = 3
		while i <= p ** (1 / 2):
			if p % i == 0:
				return i
			i += 2
		return p
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + g(n) + 2 * (k - 1))


t = int(input())
for tt in range(t):
	(n, k) = map(int, input().split())
	i = 2
	while n % i != 0:
		i += 1
	print(n + i + 2 * (k - 1))


def func(n):
	if n % 2 == 0:
		return 2
	if n % 3 == 0:
		return 3
	i = 5
	while i * i <= n:
		if n % i == 0:
			return i
		if n % (i + 2) == 0:
			return i + 2
		i = i + 6
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	ld = func(n)
	print(n + ld + (k - 1) * 2)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())

	def f(a):
		for i in range(2, a + 1):
			if a % i == 0:
				return i
	c = f(a)
	a = a + c
	a = a + 2 * (b - 1)
	print(a)


import math
t = int(input())
for tc in range(t):
	l = []
	(a, b) = map(int, input().strip().split())
	for i in range(1, int(math.sqrt(a)) + 1):
		if a % i == 0:
			l.append(i)
			l.append(a // i)
	l.remove(1)
	if len(l) == 2:
		print(2 * a + 2 * (b - 1))
	elif a % 2 == 0:
		print(a + 2 * b)
	elif b == 0:
		print(a)
	else:
		print(a + min(l) + 2 * (b - 1))


def f(m, x):
	for i in range(2, x + 1):
		if m % i == 0:
			return i
	return m

def resolve():
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		x = int(a ** 0.5) + 1
		while b > 0:
			diff = f(a, x)
			if diff == x:
				a += diff * b
				break
			a += diff
			x = diff
			b -= 1
		print(a)
resolve()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	temp = n
	for i in range(2, 10000000):
		if n % i == 0:
			temp = i
			break
	print(n + temp + 2 * (k - 1))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	flag = 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			lowest = i
			flag = 1
			break
	if flag == 0:
		lowest = n
	if n % 2 == 0:
		print(n + lowest * k)
	elif flag == 1:
		if k == 1:
			print(n + lowest)
		elif k >= 2:
			print(n + lowest + 2 * (k - 1))
	elif k == 1:
		print(2 * n)
	elif k >= 2:
		print(2 * n + 2 * (k - 1))


def solve():
	(n, k) = [int(v) for v in input().split()]
	if n % 2 != 0:
		div = 2
		found = False
		while div * div <= n:
			if n % div == 0:
				found = True
				break
			div += 1
		if found:
			n += div
		else:
			n += n
		k -= 1
	n += k * 2
	print(n)
t = int(input())
for _ in range(t):
	solve()


t = int(input())

def sm(x):
	for p in range(3, x + 1, 2):
		if x % p == 0:
			return p
			break
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		n = n + 2 * k
	else:
		n = n + sm(n) + 2 * (k - 1)
	print(n)


tc = int(input())
while tc != 0:
	tc -= 1
	(n, k) = map(int, input().split())
	i = 2
	p = n
	while i * i <= n:
		if n % i == 0:
			p = min(p, i, n // i)
		i += 1
	print(p + n + (k - 1) * 2)


z = lambda : map(int, input().split())
for _ in ' ' * int(input()):
	(a, b) = z()
	n = 0
	c = 0
	for i in range(2, int(a ** 0.5) + 1):
		if a % i == 0:
			n = 1
			c = i
			break
	if not n:
		c = a
	a += c
	a += 2 * (b - 1)
	print(a)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

class Prime:

	def __init__(self, n):
		self.M = m = int(math.sqrt(n)) + 10
		self.A = a = [True] * m
		a[0] = a[1] = False
		self.T = t = [2]
		for j in range(4, m, 2):
			a[j] = False
		for i in range(3, m, 2):
			if not a[i]:
				continue
			t.append(i)
			for j in range(i * i, m, i):
				a[j] = False
		self.ds_memo = {}
		self.ds_memo[1] = set([1])

	def is_prime(self, n):
		return self.A[n]

	def division(self, n):
		d = collections.defaultdict(int)
		for c in self.T:
			while n % c == 0:
				return c
				d[c] += 1
				n //= c
			if n < 2:
				break
		if n > 1:
			d[n] += 1
		return n

	def divisions(self, n):
		if n in self.ds_memo:
			return self.ds_memo[n]
		for c in self.T:
			if n % c == 0:
				rs = set([c])
				for cc in self.divisions(n // c):
					rs.add(cc)
					rs.add(cc * c)
				self.ds_memo[n] = rs
				return rs
		rs = set([1, n])
		self.ds_memo[n] = rs
		return rs

	def sowa(self, n):
		r = 1
		for (k, v) in self.division(n):
			t = 1
			for i in range(1, v + 1):
				t += math.pow(k, i)
			r *= t
		return r

def main():
	t = I()
	pr = Prime(10 ** 7)
	rr = []
	for _ in range(t):
		(n, k) = LI()
		for i in range(k):
			d = pr.division(n)
			if d == 2:
				n += d * (k - i)
				break
			n += d
		rr.append(n)
	return JA(rr, '\n')
print(main())


t = int(input())
for case in range(t):
	(n, k) = map(int, input().split())
	found = False
	for i in range(2, int(n ** 0.5) + 2):
		if n % i == 0:
			found = True
			n += i
			break
	if not found:
		n *= 2
	n += (k - 1) * 2
	print(n)


t = int(input())
for j in range(t):
	(x, y) = map(int, input().split())
	if x % 2 == 0:
		print(x + y * 2)
	else:
		i = 3
		while x % i != 0:
			i += 2
		print(x + i + (y - 1) * 2)


def answer():
	nk = input().split()
	(n, k) = (int(nk[0]), int(nk[1]))
	for i in range(2, n + 1):
		if n % i == 0:
			n += i
			break
	return n + (k - 1) * 2
for _ in range(int(input())):
	print(answer())


def prime(n):
	c = 0
	for i in range(2, n // 2 + 1):
		if n % i == 0:
			c = 1
			x = i
			break
	if c == 0:
		return n
	else:
		return x
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n & 1:
		n += prime(n)
		n += 2 * (k - 1)
	else:
		n += 2 * k
	print(n)


def solve():
	(n, k) = map(int, input().split())
	(div, i) = (-1, 2)
	while i ** 2 <= n:
		if n % i == 0:
			div = i
			break
		else:
			i += 1
	if div == -1:
		div = n
	print(n + div + 2 * (k - 1))
for _ in range(int(input())):
	solve()


def solve(n, k):
	for i in range(k):
		if n % 2 == 0:
			n = n + 2 * (k - i)
			break
		else:
			for j in range(2, n + 1):
				if n % j == 0:
					n = n + j
					break
	return n
num = int(input())
for _ in range(num):
	(n, k) = [int(i) for i in input().split()]
	ans = solve(n, k)
	print(ans)


LIM = int((10 ** 6) ** 0.5) + 20
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	for d in range(2, LIM):
		if n % d == 0:
			print(n + d + 2 * (k - 1))
			break
	else:
		print(n * 2 + 2 * (k - 1))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		d = 0
		for x in range(2, n + 1):
			if n % x == 0:
				d = x
				break
		print(n + 2 * (k - 1) + d)


def to_list(s):
	return list(map(lambda x: int(x), s.split(' ')))

def get_first_del(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i

def solve(n, k):
	sum_ = n
	sum_ += get_first_del(n)
	sum_ += (k - 1) * 2
	return str(sum_)
answers = []
t = int(input())
for i in range(t):
	(n, k) = to_list(input())
	answers.append(solve(n, k))
print('\n'.join(answers))


def func():
	(a, b) = map(int, input().split())
	if a % 2 == 0:
		a = a + 2 * b
	else:
		j = 2
		while a % j != 0:
			j += 1
		a = a + j + 2 * (b - 1)
	print(a)
t = int(input())
for i in range(t):
	func()


t = int(input())

def f(n):
	for i in range(2, n + 1):
		if n % i == 0:
			break
	return i
ans = []
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	if f(n) == 2:
		n += 2 * k
	else:
		n += f(n) + 2 * (k - 1)
	ans.append(n)
[print(i) for i in ans]


def solve():
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		return n + 2 * k
	i = 3
	while i * i <= n:
		if n % i == 0:
			return n + i + 2 * (k - 1)
		i += 2
	return n + n + 2 * (k - 1)
t = int(input())
for i in range(t):
	print(solve())


test_case = int(input())
my_list = []
for i in range(test_case):
	my_list.append([int(j) for j in input().split()])
for j in range(test_case):
	prime = False
	a = 0
	for k in range(2, my_list[j][0] + 1):
		if my_list[j][0] % k == 0:
			a = k
			break
	print(my_list[j][0] + a + 2 * (my_list[j][1] - 1))


def smallestDivisor(n):
	if n & 1 ^ 1:
		return 2
	else:
		d = 3
		while n % d and d < n / d:
			d += 2
		if n % d == 0:
			return d
	return n
T = int(input())
for t in range(T):
	(n, k) = list(map(int, input().strip().split(' ')))
	print(n + smallestDivisor(n) + (k - 1) * 2)


def delt(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return i
	return n
kl = int(input())
for l in range(kl):
	(n, k) = map(int, input().split())
	if n % 2 == 1:
		print(delt(n) + n + 2 * (k - 1))
	else:
		print(n + 2 * k)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	di = 0
	if n % 2 == 0:
		di = 2
	else:
		for i in range(2, int((n + 1) ** 0.5) + 1):
			if n % i == 0:
				di = i
				break
	if di == 0:
		di = n
	x = di + n
	print(x + (k - 1) * 2)


dividers = [0] * 1000001
for i in range(2, 1000):
	if dividers[i] != 0:
		continue
	next_i = i
	while next_i < 1000001:
		if dividers[next_i] == 0:
			dividers[next_i] = i
		next_i += i
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	div = dividers[n]
	if div == 2:
		print(n + 2 * k)
	else:
		if not div:
			div = n
		print(n + div + 2 * (k - 1))


def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	while k > 0:
		if n % 2 == 0:
			n += 2 * k
			k = 0
		else:
			n += smallestDivisor(n)
			k -= 1
	print(n)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	s = 0
	r = 0
	for l in range(2, int(n / 2) + 2):
		if n % l == 0:
			s = n + l
			r = 1
			break
	if r == 0:
		s = 2 * n
	print(s + (k - 1) * 2)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	divisor = 2
	while divisor <= math.sqrt(n):
		if n % divisor == 0:
			break
		divisor += 1
	n += divisor if divisor <= math.sqrt(n) else n
	k -= 1
	print(n + 2 * k)


for t in range(int(input())):
	A = list(map(int, input().split()))
	n = A[0]
	k = A[1]
	f = 2
	flag = True
	while f <= n ** 0.5:
		if n % f == 0:
			n += f
			flag = False
			break
		f += 1
	if flag:
		n += n
	if k == 1:
		print(n)
	else:
		calc = (k - 1) * 2
		n += calc
		print(n)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		num = 3
		while n % num != 0:
			num += 1
		print(n + 2 * (k - 1) + num)


import functools

@functools.lru_cache(None)
def f(num: int) -> tuple:
	for i in range(2, num):
		(q, r) = divmod(num, i)
		if r == 0:
			return (i, q)
	return (num, 1)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(a, b) = f(n)
	if a == n:
		print(2 * n + 2 * (k - 1))
	elif b % 2 == 1:
		print(n + a + 2 * (k - 1))
	else:
		print(n + a * k)


t = int(input())
for i in range(t):
	arr = input().split()
	n = int(arr[0])
	k = int(arr[1])
	ans = 0
	if n % 2 == 0:
		val = 2 * k
		ans = n + val
	else:
		j = 2
		val = 0
		while j <= n:
			if n % j == 0:
				val += j
				break
			j += 1
		val += (k - 1) * 2
		ans = n + val
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2:
		for i in range(2, int(n ** (1 / 2)) + 5):
			if n % i == 0:
				f = i
				break
		else:
			f = n
		n += f
		k -= 1
	ans = n + k * 2
	print(ans)


from math import sqrt
t = int(input())
for tc in range(t):
	s = input().split()
	(n, k) = (int(s[0]), int(s[1]))
	if n % 2 == 0:
		n += 2 * k
		print(n)
	else:
		f = 0
		x = int(sqrt(n)) + 1
		for j in range(2, x):
			if n % j == 0:
				va = j
				k -= 1
				f = 1
				break
		if f == 0:
			n += n
			k -= 1
			n += 2 * k
			print(n)
		else:
			n += va
			n += 2 * k
			print(n)


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, k) = get_ints()
	if n % 2 == 0:
		n = n + 2 * k
		print(n)
	else:
		f = 0
		for i in range(2, n + 1):
			if n % i == 0:
				break
		n = n + i
		n = n + 2 * (k - 1)
		print(n)


from math import sqrt

def divisor(number):
	if number % 2 == 0:
		return 2
	else:
		for i in range(3, int(sqrt(number)) + 1, 2):
			if number % i == 0:
				return i
		return number
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n & 1:
		result = n + 2 * (k - 1) + divisor(n)
		print(result)
	else:
		result = n + 2 * k
		print(result)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	fmd = 1
	for m in range(2, n + 1):
		if n % m == 0:
			fmd = m
			break
	n += fmd + 2 * (k - 1)
	print(n)


def small_div(n):
	if n % 2 == 0:
		return 2
	else:
		i = 3
		while i * i <= n:
			if n % i == 0:
				return i
			i = i + 2
		return n
times = int(input())
i = 1
while i <= times:
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	sd = small_div(n)
	if sd % 2 == 0:
		n = n + 2 * k
	else:
		n = n + sd + 2 * (k - 1)
	print(n)
	i = i + 1


def Hello(n, k):
	if n % 2 == 0:
		n += 2 * k
		return n
	else:
		for i in range(2, n + 1):
			if n % i == 0:
				p = i
				break
		n += p
		n += 2 * (k - 1)
		return n
t = int(input())
for _ in range(t):
	nk = input().split()
	(n, k) = (int(nk[0]), int(nk[1]))
	print(Hello(n, k))


from math import sqrt, ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = n
	flag = 0
	for i in range(2, ceil(sqrt(n)) + 1):
		if n % i == 0:
			flag = 1
			break
	if flag == 1:
		s += i
	else:
		s += n
	s += (k - 1) * 2
	print(s)


T_ON = 1
DEBUG_ON = 1
MOD = 998244353

def solve():
	(n, k) = read_ints()

	def f(n):
		for i in range(2, n + 1):
			if n % i == 0:
				return i
	i = 0
	while i < k:
		fn = f(n)
		n += fn
		i += 1
		if fn == 2:
			n += 2 * (k - i)
			break
	print(n)

def main():
	T = read_int() if T_ON else 1
	for i in range(T):
		solve()

def debug(*xargs):
	if DEBUG_ON:
		print(*xargs)
from collections import *
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def read_int():
	return int(input())

def read_ints():
	return list(map(int, input().split()))

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def First():
	print('First')

def Second():
	print('Second')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

def fib_to_n(n):
	f = []
	(a, b) = (0, 1)
	while a <= n:
		f.append(a)
		(a, b) = (b, a + b)
	return f

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def lcm(a, b):
	d = gcd(a, b)
	return a * b // d

def is_even(x):
	return x % 2 == 0

def is_odd(x):
	return x % 2 == 1

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, int(n ** 0.5) + 1):
		if n % i:
			return False
	return True

def gen_primes(n):
	P = [True for _ in range(n + 1)]
	P[0] = P[1] = False
	for i in range(int(n ** 0.5) + 1):
		if P[i]:
			for j in range(2 * i, n + 1, i):
				P[j] = False
	return P

def is_lucky(n):
	return set(list(str(n))).issubset({'4', '7'})
main()


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		n += 2 * k
	elif k == 1:
		n = 2 * n
	else:
		ele = -1
		for i in range(3, n + 1):
			if n % i == 0:
				ele = i
				break
		n = n + ele
		n += 2 * (k - 1)
	print(n)


t = int(input())
tuple = []
for _ in range(t):
	(n, k) = map(int, input().split())
	tuple.append((n, k))
for (n, k) in tuple:
	for i in range(2, n + 1):
		if n % i == 0:
			ans = i + n + (k - 1) * 2
			break
	print(ans)


import math
import operator

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def AcDegaYe():
	(n, k) = map(int, input().split())
	x = smallestDivisor(n)
	print(n + x + (k - 1) * 2)
t = int(input())
for _ in range(t):
	AcDegaYe()


import math as mt
MAXN = 1000001
spf = [0 for i in range(MAXN)]

def sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, mt.ceil(mt.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def getFactorization(x):
	ret = list()
	while x != 1:
		ret.append(spf[x])
		x = x // spf[x]
	return ret
sieve()
for lo in range(int(input())):
	(n, k) = map(int, input().split())
	s = spf[n]
	n += s
	n += 2 * (k - 1)
	print(n)


for s in [*open(0)][1:]:
	(n, k) = map(int, s.split())
	d = 2
	while n % d:
		d += 1
	print(n + d + 2 * k - 2)


divs = dict()

def get_div(n):
	if n in divs:
		div = divs[n]
		return div
	for div in range(2, n + 1):
		if n % div == 0:
			return div

def solve():
	(n, k) = map(int, input().split())
	div = get_div(n)
	result = n + div + (k - 1) * 2
	print(result)

def main():
	for _ in range(int(input())):
		solve()
main()


import sys

def test():
	stdin = sys.stdin
	sys.stdin = open('input.txt')
	main()
	sys.stdin = stdin

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = [int(x) for x in input().split()]
		for d in range(2, n + 1):
			if n % d == 0:
				ans = n + d + 2 * (k - 1)
				break
		print(ans)
main()


from sys import stdin, exit
from math import ceil, sqrt
input = stdin.readline

def i():
	return input()

def ii():
	return int(input())

def iis():
	return map(int, input().split())

def liis():
	return list(map(int, input().split()))

def print_array(a):
	print(' '.join(map(str, a)))
t = ii()
for _ in range(t):
	(n, k) = iis()
	can = False
	orig = n
	if orig % 2 == 0:
		print(n + k * 2)
	else:
		found = False
		for i in range(2, ceil(sqrt(n)) + 1):
			if n % i == 0:
				n += i
				k -= 1
				found = True
				break
		if not found:
			n += n
			k -= 1
		print(n + k * 2)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	while True:
		if n % 2 == 0:
			print(n + k * 2)
			break
		for i in range(2, n + 1):
			if n % i == 0:
				n += i
				k -= 1
				break


import sys

def main():
	t = int(input())
	primeList = [True] * (10 ** 6 + 1)
	primeList[0] = False
	primeList[1] = True
	prime = []
	for i in range(2, 10 ** 6 + 1):
		if primeList[i]:
			cnt = 2 * i
			prime.append(i)
			while cnt <= 10 ** 6:
				primeList[cnt] = False
				cnt += i
	for _ in range(t):
		(a, b) = map(int, sys.stdin.readline().split())
		ans = a
		if a % 2:
			if a in prime:
				ans += a
				b -= 1
			else:
				for i in prime:
					if not a % i:
						ans += i
						b -= 1
						break
		if b > 0:
			ans += 2 * b
		print(ans)
	return
main()


def f(n):
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = int(input())
while t:
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if n % 2 == 0:
		n = n + 2 * k
	else:
		n = n + f(n)
		n = n + 2 * (k - 1)
	print(n)
	t -= 1


def f(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i

def orac_factor():
	(n, k) = map(int, input().split())
	fn = f(n)
	print(fn + n + (k - 1) * 2)
t = int(input())
for loop in range(t):
	orac_factor()


import sys
import math
import bisect

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		while k:
			for i in range(2, n + 1):
				if n % i == 0:
					m = i
					break
			if m == 2:
				n += k * 2
				k = 0
			else:
				n += m
				k -= 1
		print(n)
main()


def solve():
	n = int(input())
	l = list(str(n))
	k = len(l) - 1
	if n % 10 ** k == 0:
		print(1)
		print(n)
	else:
		ans = []
		for i in range(len(l)):
			if l[i] != '0':
				x = int(l[i]) * 10 ** k
				ans.append(x)
			k -= 1
		print(len(ans))
		print(*ans)

def fun(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def solve():
	(n, k) = map(int, input().split())
	if k == 1:
		print(n + fun(n))
	elif n % 2 == 0:
		print(n + k * fun(n))
	else:
		x = fun(n) + n
		print(x + (k - 1) * fun(x))
try:
	for _ in range(int(input())):
		solve()
except:
	pass


def div(n, k):
	if n % 2 == 0:
		return n + k * 2
	else:
		for i in range(2, n + 1):
			if n % i == 0:
				p = i
				break
		return n + p + (k - 1) * 2
t = int(input())
ans = []
for i in range(t):
	nk = list(map(int, input().rstrip().split()))
	n = int(nk[0])
	k = int(nk[1])
	result = div(n, k)
	ans.append(result)
for i in ans:
	print(i)


import sys
import math
from collections import defaultdict
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
for t in range(int(input())):
	(n, k) = intInp()
	if n % 2 == 0:
		print(2 * k + n)
	else:
		div = 2
		while div <= n:
			if n % div == 0:
				break
			div += 1
		print(div + n + 2 * (k - 1))


from sys import stdin, stdout

def find(K, N):
	if N % 2 == 0:
		return N + 2 * K
	i = 3
	for i in range(3, N + 1, 2):
		if N % i == 0:
			break
	return N + 2 * (K - 1) + i

def main():
	for _ in range(int(stdin.readline())):
		(N, K) = list(map(int, stdin.readline().split()))
		print(find(K, N))
main()


def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for tin in range(int(input())):
	(n, k) = map(int, input().split())
	i = 0
	for _ in range(k):
		n = n + smallestDivisor(n)
		if n % 2 == 0:
			i = _
			break
	n = 2 * (k - i - 1) + n
	print(n)


import math

def get_smallest_divisor(n):
	if n <= 3:
		return n
	sqrt = int(math.sqrt(n))
	for i in range(2, sqrt + 1):
		if n % i == 0:
			return i
	return n
n_t = int(input())
for i in range(n_t):
	(n, k) = [int(x) for x in input().split()]
	if n % 2 == 0:
		print(f'{n + 2 * k}')
	else:
		sd = get_smallest_divisor(n)
		print(n + sd + 2 * (k - 1))


import sys

def read_integer():
	return int(sys.stdin.readline())

def read_integers():
	return [int(x) for x in sys.stdin.readline().split(' ')]

def print_integers(nums):
	print(' '.join([str(x) for x in nums]))

def func(inputs):
	(num, k) = (inputs[0], inputs[1])
	ans = num
	upper = num
	for i in range(k):
		if upper == 2:
			ans += 2 * (k - i)
			break
		for x in range(2, upper + 1):
			if num % x == 0:
				ans += x
				num += x
				upper = x
				break
	return ans
n = read_integer()
for _ in range(n):
	print(func(read_integers()))


import math

def solve(n, k):
	while k and n % 2 == 1:
		root = math.floor(math.sqrt(n))
		i = 2
		while i <= root:
			if n % i == 0:
				n += i
				break
			i += 1
		else:
			n += n
		k -= 1
	if k:
		n += k * 2
	return n

def main():
	tests = int(input())
	while tests:
		n_k = input().split()
		print(solve(int(n_k[0]), int(n_k[1])))
		tests -= 1
main()


from sys import stdin
from heapq import nsmallest
ip = stdin.readline
for _ in range(int(ip())):
	(n, k) = map(int, ip().split())
	smallestdivisor = 0
	for i in range(2, (n >> 1) + 1):
		if n % i == 0:
			smallestdivisor = i
			break
	if smallestdivisor:
		print(n + smallestdivisor + 2 * (k - 1))
	else:
		print(2 * (n + k - 1))


res = ''
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		res += str(n + k * 2) + '\n'
	else:
		curr = n
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				curr += i
				break
		if curr == n:
			curr += n
		res += str(curr + 2 * (k - 1)) + '\n'
print(res)


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		ans = n + k * 2
		print(ans)
	else:
		res = 1
		for i in range(3, n + 1):
			if n % i == 0:
				res = i
				break
		ans = n + res + (k - 1) * 2
		print(ans)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = []
	for i in range(2, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(n // i)
				l.append(i)
	if not l:
		l.append(n)
	l.sort()
	print(n + l[0] + 2 * (k - 1))


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		n += 2 * k
	else:
		i = 2
		while i <= n:
			if n % i == 0:
				break
			else:
				i += 1
		n += i + 2 * (k - 1)
	print(n)
	t -= 1


t = int(input())
import math

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
import math
for i in range(t):
	(n, k) = map(int, input().strip().split())
	if n % 2 == 0:
		print(n + 2 + (k - 1) * 2)
	elif n % 3 == 0:
		print(n + 3 + (k - 1) * 2)
	elif n % 5 == 0:
		print(n + 5 + (k - 1) * 2)
	else:
		r = smallestDivisor(n)
		print(n + r + (k - 1) * 2)


import sys
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def divisor(n):
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			yield i
			if i != n // i:
				yield (n // i)

def slv(N, K):
	d = list(divisor(N))
	d.sort()
	K -= 1
	n = N + d[1]
	ans = 2 * K + n
	return ans

def main():
	T = read_int()
	for _ in range(T):
		(N, K) = read_int_n()
		print(slv(N, K))
main()


import math

class sol:

	def __init__(self):
		return

	def find(self, num):
		r = -1
		savenum = num
		i = 3
		while i * i <= num:
			if num % i == 0:
				r = i
				break
			i += 1
		if r == -1:
			r = savenum
		return r
T = int(input())
x = sol()
for i in range(T):
	(n, k) = map(int, input().split())
	c = n
	if c % 2 == 0:
		print(str(c + 2 * k))
	else:
		r = x.find(c)
		print(c + 2 * (k - 1) + r)


def lowest_factor(x):
	fact = 0
	for i in range(2, int(x ** (1 / 2)) + 1):
		if x % i == 0:
			fact = i
			break
	return fact if fact != 0 else x
q = int(input())
for _ in range(q):
	(n, k) = map(int, input().split())
	print(2 * k + n if n % 2 == 0 else n + (k - 1) * 2 + lowest_factor(n))


t = int(input())

def check(x, y):
	p = 0
	if x % 2 == 0:
		print(x + 2 * y)
	else:
		for i in range(3, n + 1, 2):
			if x % i == 0:
				p = i
				break
		print(x + p + 2 * (y - 1))
for _ in range(t):
	(n, m) = map(int, input().split())
	check(n, m)


testcases = int(input())
for i in range(testcases):
	(n, k) = list(map(int, input().split()))
	stop = True
	if n % 2 == 0:
		print(2 * k + n)
		stop = False
	else:
		for i in range(2, n + 1):
			if n % i == 0:
				n += i
				break
	if stop:
		print(2 * (k - 1) + n)


from math import sqrt

def f(n):
	for i in range(2, int(sqrt(n) + 1)):
		if n % i == 0:
			return i
			break
	else:
		return n
for i in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n
	while k:
		if f(ans) == 2:
			ans = k * 2 + ans
			break
		ans = ans + f(ans)
		k -= 1
	print(ans)


def f(n):
	i = 2
	for i in range(2, int(pow(n, 0.5)) + 1):
		if n % i == 0:
			break
	if n % i != 0:
		i = n
	return i
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if n % 2:
		n = n + f(n) + 2 * (k - 1)
	else:
		n = n + 2 * k
	print(n)


import sys

def numSp():
	return map(int, sys.stdin.readline().split())

def numSg():
	return int(sys.stdin.readline().strip())

def numL():
	return list(map(int, sys.stdin.readline().split()))
t = numSg()
for j in range(t):
	(a, b) = numSp()
	n = 0
	for i in range(2, a + 1):
		if a % i == 0:
			n = i
			break
	print(a + n + 2 * (b - 1))


def solve():
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		i = 3
		is_prime = True
		while i * i <= n:
			if n % i == 0:
				n += i
				is_prime = False
				break
			i += 1
		if is_prime:
			n += n
		print(n + 2 * (k - 1))
for _ in range(int(input())):
	solve()


import math
d = {}

def compute(i, j):
	output = i
	for k in range(j):
		if output % 2 == 0:
			return output + (j - k) * 2
		sf = smallest_factor(output)
		output += sf
	return output

def smallest_factor(j):
	if j in d:
		return d[j]
	for t in range(2, int(math.sqrt(j)) + 1):
		if j % t == 0:
			d[j] = t
			return t
	return j
i = int(input())
l = []
for j in range(i):
	t = list(map(int, input().split(' ')))
	l.append(t)
for (i, j) in l:
	t = compute(i, j)
	print(t)


def f(n):
	if n <= 3:
		return n
	if n % 2 == 0:
		return 2
	elif n % 3 == 0:
		return 3
	i = 5
	while i * i <= n:
		if n % i == 0:
			return i
		elif n % (i + 2) == 0:
			return i + 2
		i = i + 6
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	while k:
		x = f(n)
		n += x
		k -= 1
		if x == 2:
			n += k * 2
			break
	print(n)


def find_largest_factor(N):
	p = int(N ** 0.5 // 1 + 1)
	for i in range(3, p, 2):
		if N % i == 0:
			return i
	return N
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if n & 1:
		factor = find_largest_factor(n)
		n += factor
		k -= 1
	print(n + k * 2)


def abc(n):
	i = 2
	while True:
		if not n % i:
			return i
		i += 1
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	n = abc(n) + n
	n = n + 2 * (k - 1)
	print(n)


def builder(n, k):
	if n % 2 == 0:
		return n + 2 * k
	else:
		p = 0
		for i in range(n, 1, -1):
			if n % i == 0:
				p = i
		return n + p + 2 * (k - 1)
for _ in range(int(input())):
	(x, y) = [int(i) for i in input().split()]
	print(builder(x, y))


from collections import Counter, defaultdict, deque
import sys
input = sys.stdin.readline

def primes(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return factors

def solve():
	(n, k) = [int(x) for x in input().split()]
	m = primes(n)
	print(n + min(m) + 2 * (k - 1))
tt = int(input())
for test in range(tt):
	solve()


def f_n(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def solve(vec):
	for i in vec:
		n = i[0]
		if n % 2 == 0:
			n = n + i[1] * f_n(n)
		else:
			n = n + f_n(n)
			n = n + (i[1] - 1) * f_n(n)
		print(n)
t = int(input())
vec = []
for i in range(t):
	string = input().split(' ')
	vec.append([int(_) for _ in string])
solve(vec)


test = int(input())

def f(n):
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n
for i in range(test):
	(n, k) = [int(i) for i in input().split()]
	if n % 2:
		n += f(n)
		n += 2 * (k - 1)
	elif not n % 2:
		n += 2 * k
	print(n)


from math import floor

def f(n):
	for i in range(2, 1 + floor(n ** 0.5)):
		if n % i == 0:
			return i
	return n
for t in range(int(input())):
	(n, k) = map(int, input().split(' '))
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + 2 * (k - 1) + f(n))


MAX = 1000000
prime = [True for i in range(MAX + 1)]
primes = []

def sv(n):
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	for i in range(len(prime)):
		if prime[i]:
			primes.append(i)
sv(MAX)

def getSmall(n):
	if prime[n]:
		return n
	for p in primes:
		if n % p == 0:
			return p
	return n

def solve(n, k):
	small = getSmall(n)
	if n % 2 == 0:
		return n + k * 2
	else:
		return small + n + (k - 1) * 2
for _ in range(int(input())):
	(n, k) = map(int, input().strip().split(' '))
	print(solve(n, k))


import math
for t in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if n % 2 == 0:
		n = 2 * k + n
	else:
		for i in range(3, n + 1, 2):
			if n % i == 0:
				n = n + i
				break
		n = 2 * (k - 1) + n
	print(n)


from math import sqrt

def func(n):
	x = n
	if n % 2 == 0:
		return 2
	for j in range(2, int(sqrt(n)) + 1):
		if n % j == 0:
			x = j
			break
	return x
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	n += func(n) + (k - 1) * 2
	print(n)


def main():
	t = int(input())
	for i in range(t):
		(n, k) = map(int, input().split())
		if n % 2 == 0:
			print(n + 2 * k)
			continue
		p = 0
		for j in range(n, 2, -1):
			if n % j == 0:
				p = j
		print(n + p + 2 * (k - 1))
main()


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	fact = 2
	while fact < n:
		if n % fact == 0:
			break
		fact += 1
	res = n + fact + (k - 1) * 2
	print(res)


t = int(input())
for i in range(t):
	a = [int(i) for i in input().split()]
	n = a[0]
	k = a[1]
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		i = 3
		x = 0
		while x == 0:
			if n % i == 0:
				x = n + i + 2 * (k - 1)
				print(x)
			else:
				i += 2


def isPrime(n):
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def main():
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		return n + 2 * k
	elif isPrime(n):
		return 2 * n + 2 * (k - 1)
	else:
		i = 2
		while i and k:
			if n % i == 0:
				n += i
				k -= 1
			if n % 2 == 0:
				return n + 2 * k
				break
			i += 1
		return n
t = int(input())
while t:
	t -= 1
	print(main())


t = int(input())
for test in range(t):
	(n, k) = [int(x) for x in input().split()]
	f = -1
	if n % 2 == 0:
		f = 2
		print(n + f * k)
		continue
	else:
		import math
		for i in range(3, int(math.sqrt(n)) + 1, 2):
			if n % i == 0:
				f = i
				break
		if f != -1:
			n = n + f
			k -= 1
			if n % 2 == 0:
				print(n + 2 * k)
				continue
	if f == -1:
		f = n
		n += f
		k -= 1
		print(n + 2 * k)


z = int(input())
for h in range(z):
	(n, k) = map(int, input().split())
	if n % 2 == 0 and n != 1:
		x = 2
		k -= 1
	elif n == 1:
		x = 1
		k -= 1
	else:
		for i in range(3, n + 1):
			if n % i == 0:
				x = i
				k -= 1
				break
	n = n + x
	n = n + 2 * k
	print(n)


import math
t = int(input())
for T in range(t):
	(n, k) = map(int, input().split())
	for i in range(2, n + 1):
		if n % i == 0:
			n += i
			break
	n += 2 * (k - 1)
	print(n)


import sys
from math import ceil, sqrt
read = sys.stdin.buffer.readline
mi = lambda : map(int, read().split())
li = lambda : list(mi())
cin = lambda : int(read())
for _ in range(cin()):
	(n, k) = mi()
	i = 2
	sq = n
	while i * i <= n:
		if n % i == 0:
			sq = min(sq, i, n // i)
		i += 1
	n += sq
	print(n + 2 * (k - 1))


import math as mt
MAXN = 1000007
spf = [0 for i in range(MAXN)]

def sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, mt.ceil(mt.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def getFactorization(x):
	ret = list()
	while x != 1:
		ret.append(spf[x])
		x = x // spf[x]
	return ret[0]
t = int(input())
sieve()
while t:
	(n, k) = [int(i) for i in input().split()]
	f_term = getFactorization(n) + n
	ans = f_term + 2 * (k - 1)
	print(ans)
	t -= 1


def factor(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + factor(n) + 2 * (k - 1))
	t -= 1


ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda : int(input())
ip = lambda : [int(w) for w in input().split()]
prime = []

def sieve(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
for _ in range(inp()):
	(n, k) = ip()
	while k:
		fn = 0
		if n % 2 == 0:
			n += 2 * k
			break
		else:
			for j in range(2, n + 1):
				if n % j == 0:
					fn = j
					break
		n += fn
		k -= 1
	print(n)


def helper(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
t = int(input())
for _ in range(t):
	(n, k) = input().split(' ')
	n = int(n)
	k = int(k)
	while k > 0 and n % 2 == 1:
		a = helper(n)
		n += a
		k -= 1
	print(n + k * 2)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a % 2 == 0:
		print(a + b * 2)
	else:
		val = 0
		for i in range(2, int(a ** 0.5) + 2):
			if a % i == 0:
				val = i
				break
		if val == 0:
			val = a
		a += val
		print(a + (b - 1) * 2)


def f(x):
	i = 2
	while i <= int(x ** 0.5) + 1 and x % i != 0:
		i += 1
	return i if i <= int(x ** 0.5) + 1 else x
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = f(n)
	print(n + a + 2 * (k - 1))


for t in range(int(input())):
	(n, k) = map(int, input().split(' '))
	breakFlag = False
	while not breakFlag:
		for i in range(2, n + 1):
			if n % i == 0:
				n += i
				k -= 1
				if i == 2:
					breakFlag = True
				break
	n += k * 2
	print(n)


m = int(input())
while m > 0:
	(n, k) = list(map(int, input().split()))
	if n % 2 == 1:
		for j in range(3, n + 1):
			if n % j == 0:
				n += j
				n += 2 * (k - 1)
				break
	elif n % 2 == 0:
		n += k * 2
	print(n)
	m -= 1


def chk(n, k):
	f = 1
	for i in range(2, int(n ** (1 / 2)) + 1):
		if n % i == 0:
			f = i
			break
	if f == 1:
		f = n
	n += f
	return n + (k - 1) * 2
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(chk(n, k))


i = int(input())

def foo(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0 and i != 1:
			return i
	return n
for _ in range(i):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		n = n + 2 * k
	else:
		n = n + 2 * (k - 1) + foo(n)
	print(n)


t = int(input())
for i in range(t):
	nk = list(map(int, input().split()))
	n = nk[0]
	k = nk[1]
	flag = True
	if n % 2 == 0:
		print(n + k * 2)
		continue
	else:
		for i in range(3, int(n ** 0.5) + 1, 2):
			if n % i == 0:
				print(n + i + 2 * (k - 1))
				flag = False
				break
	if flag:
		print(n + n + 2 * (k - 1))


t = int(input())

def f_divisor(x):
	for i in range(2, n + 1):
		if x % i == 0:
			return i
	return -1
while t > 0:
	(n, k) = [int(x) for x in input().split()]
	if n % 2 == 0:
		print(n + 2 * k)
	elif f_divisor(n) == -1:
		print(n + 2 * (k - 1))
	else:
		c = f_divisor(n)
		print(n + c + 2 * (k - 1))
	t = t - 1


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	div = -1
	for i in range(2, int(n * 0.5) + 1):
		if n % i == 0:
			div = i
			break
	if div == -1:
		div = n
	n += div
	k -= 1
	print(n + k * 2)


import sys
from math import sqrt
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n & 1 == 0:
		print(n + k * 2)
		continue
	for i in range(3, int(sqrt(n)) + 2, 2):
		if n % i == 0:
			print(n + i + (k - 1) * 2)
			break
	else:
		print(n * 2 + (k - 1) * 2)


t = int(input())
while t:
	inp1 = list(map(int, input().strip().split()))[:2]
	(n, k) = (inp1[0], inp1[1])
	if n % 2 == 0:
		print(n + k * 2)
	else:
		for i in range(2, n + 1):
			if n % i == 0:
				val = i
				break
		print(n + val + (k - 1) * 2)
	t -= 1


from sys import *
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = -1
	if n % 2 == 0:
		ans = n + 2 * k
	else:
		div = -1
		for i in range(2, n + 1):
			if n % i == 0:
				div = i
				break
		ans = n + div + (k - 1) * 2
	stdout.write(str(ans) + '\n')


from math import *
import sys
input = sys.stdin.buffer.readline
a = int(input())
for x in range(a):
	(b, c) = map(int, input().split())
	if b == 3:
		b += 3
	elif b == 2:
		b += 2
	elif b == 4:
		b += 2
	else:
		for z in range(2, b + 1):
			if b % z == 0:
				b += z
				break
	b = b + 2 * (c - 1)
	print(int(b))


def f(cnt):
	q = 3
	for i in range(3, cnt // 2):
		if cnt % q == 0:
			return q
		q = q + 1
	return cnt
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	cnt = n
	if n % 2 == 0:
		cnt = n + k * 2
	else:
		t = f(n)
		t = t + n
		cnt = t + 2 * (k - 1)
	print(cnt)


def checkPrime(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 0
	if n % 2 == 0:
		ans = n + 2 * k
	else:
		ans = n + 2 * (k - 1) + checkPrime(n)
	print(ans)


for _ in range(int(input())):
	ind = 0
	(n, k) = map(int, input().split())
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			ind = i
			break
	if ind == 0:
		ind = n
	x = ind + n
	x += (k - 1) * 2
	print(x)


import sys

def div(i):
	j = 2
	while j ** 2 <= i:
		if i % j == 0:
			return j
		j += 1
	return i

def solve():
	input = sys.stdin.readline
	t = int(input())
	Ans = [0] * t
	for i in range(t):
		(N, K) = map(int, input().split())
		count = 0
		while count < K:
			add = div(N)
			if add == 2:
				N += add * (K - count)
				break
			else:
				N += add
				count += 1
		Ans[i] = N
	print('\n'.join(map(str, Ans)))
	return 0
solve()


import math

def f(n):
	assert n >= 2 and n <= 10 ** 6
	for i in range(2, math.floor(n ** 0.5) + 1):
		if n % i == 0:
			return i
	return n
t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split(' ')]
	if n % 2 == 0:
		print(2 * k + n)
	else:
		print(2 * (k - 1) + n + f(n))


def lowestdevisior(n):
	if n % 2 == 0:
		return 2
	elif n % 3 == 0:
		return 3
	i = 5
	while i * i <= n:
		if n % i == 0:
			return i
		elif n % (i + 2) == 0:
			return i + 2
		i = i + 6
	return n
q = int(input())
while q:
	q -= 1
	(n, k) = map(int, input().strip().split(' '))
	x = lowestdevisior(n)
	print(n + x + 2 * (k - 1))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		n += 2 * k
	elif n % 2 == 1:
		for i in range(3, n + 1, 2):
			if n % i == 0:
				got = i
				break
		n += got
		n += 2 * (k - 1)
	print(n)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	s = 0
	fn = 0
	if n & 1 == 0:
		s = n
		s += 2 * k
		n = s
	else:
		for j in range(k):
			s = 0
			if n & 1 == 0:
				s = n
				s += 2 * (k - j)
				n = s
				break
			else:
				s += n
				for l in range(3, n + 1, 2):
					if n % l == 0:
						fn = l
						s += fn
						break
			n = s
	print(n)


def min_div(n):
	for d in range(2, 1 + int(n ** 0.5)):
		if not n % d:
			return d
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(n + min_div(n) + 2 * (k - 1))


t = int(input())
IN = [input().split(' ') for x in range(t)]

def f(x):
	for i in range(2, int(x ** (1 / 2) + 1)):
		if x % i == 0:
			return i
	return x
for (n, k) in IN:
	n = int(n)
	k = int(k)
	for i in range(k):
		if f(n) == 2:
			n += (k - i) * 2
			break
		n += f(n)
	print(n)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key, lru_cache
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip().split()]

def st():
	return str(input().rstrip())[2:-1]

def val():
	return int(input().rstrip())

def li2():
	return [str(i)[2:-1] for i in input().rstrip().split()]

def li3():
	return [int(str(i)[2:-1]) for i in input().rstrip()]
import math as mt
MAXN = 10 ** 6 + 5
spf = [0 for i in range(MAXN)]

def sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, mt.ceil(mt.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
sieve()
for _ in range(val()):
	(n, k) = li()
	print(n + spf[n] + (k - 1) * 2)


def sieve(n, prime):
	visit = [False] * (n + 1)
	for x in range(2, n + 1):
		if visit[x] == False:
			prime.append(x)
			j = x + x
			while j <= n:
				visit[j] = True
				j = j + x
t = int(input())
i = 0
prime = []
import math
sieve(math.ceil(math.sqrt(10 ** 6)), prime)
while i < t:
	(n, k) = map(int, input().split())
	j = 0
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		ans = 0
		a = False
		for x in prime:
			if n % x == 0:
				a = True
				ans = x
				break
		if a == True:
			print(n + ans + 2 * (k - 1))
		else:
			print(n + n + 2 * (k - 1))
	i = i + 1


t = int(input())
for _ in range(t):
	(N, K) = map(int, input().split())
	div = N
	if N % 2 == 0:
		print(N + 2 * K)
		continue
	for i in range(2, int(N ** 0.5) + 1):
		if N % i == 0:
			div = i
			break
	if K == 1:
		print(N + div)
		continue
	print(N + div + 2 * (K - 1))


def Divisors(n):
	i = 2
	while i <= n:
		if n % i == 0:
			l1 = i
			break
		i = i + 1
	return l1
t = int(input())
for p in range(t):
	(n, k) = map(int, input().split())
	sum = n
	if n % 2 == 0:
		sum = n + 2 * k
	else:
		first_step = Divisors(n)
		sum = first_step + n + (k - 1) * 2
	print(sum)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	(n, k) = sp()
	if n & 1:
		j = 2
		i = n
		while j * j <= n:
			if n % j == 0:
				i = j
				break
			j += 1
		answer = n + i + (k - 1) * 2
	else:
		answer = n + k * 2
	out(answer)


def my_func(n):
	j = 0
	flag = 0
	for j in range(2, int(pow(n, 0.5)) + 1):
		if n % j == 0:
			flag = 1
			break
	if flag == 0:
		j = n
	return j
for j in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2:
		n = my_func(n) + n
		k -= 1
	print(n + 2 * k)


from math import sqrt
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	for i in range(k):
		flag = 0
		for j in range(2, int(sqrt(n)) + 1):
			if n % j == 0:
				flag = 1
				break
		if flag == 0:
			j = n
		if j == 2:
			n += 2 * (k - i)
			break
		n += j
	print(n)


def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def find(n, k):
	if n % 2 == 0:
		return n + 2 * k
	if isPrime(n):
		return find(n + n, k - 1)
	else:
		for z in range(2, n):
			if n % z == 0:
				return find(n + z, k - 1)
tc = int(input())
for _ in range(tc):
	(n, k) = list(map(int, input().split()))
	print(find(n, k))


MAXN = 1000001
prime_seive = [0] * MAXN

def seive_orac_factors():
	prime_seive[2] = 2
	for i in range(3, MAXN, 2):
		prime_seive[i] = i
	for j in range(3, MAXN):
		if j == prime_seive[j]:
			for k in range(j * j, MAXN, j):
				if k & 1:
					prime_seive[k] = min(prime_seive[k], j)

def orac_factors(n, k):
	while k > 0:
		if n & 1 and prime_seive[n] & 1:
			k -= 1
			n = prime_seive[n] + n
			break
		if n % 2 == 0:
			k -= 1
			n = 2 + n
			break
		else:
			n = prime_seive[n] + n
			k -= 1
	if k > 0:
		n = n + 2 * k
	return n
seive_orac_factors()
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	print(orac_factors(n, k))


from math import sqrt
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	for j in range(2, int(sqrt(n)) + 1):
		if n % j == 0:
			n += j
			break
	else:
		n += n
	print(n + (k - 1) * 2)


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [Scanner.string() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [Scanner.int() for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

def pop_count(x):
	x = x - (x >> 1 & 6148914691236517205)
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	x = x + (x >> 8)
	x = x + (x >> 16)
	x = x + (x >> 32)
	return x & 127
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def solve():
	(N, K) = Scanner.map_int()
	if N % 2 == 0:
		print(2 * K + N)
	else:
		print(2 * (K - 1) + N + sorted(Math.divisor(N))[1])

def main():
	T = Scanner.int()
	for _ in range(T):
		solve()
main()


import math
t = int(input())
for _ in range(t):
	(n, q) = map(int, input().split())
	if n == 2:
		i = 2
	for i in range(2, int(math.sqrt(n)) + 2):
		if n % i == 0:
			break
	if n % i != 0:
		i = n
	print(n + i + (q - 1) * 2)


from sys import stdin, stdout
import heapq
import cProfile, math
from collections import Counter, defaultdict, deque
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
import sys
from random import randint

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def smallest(n):
	i = 2
	while i * i <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	(n, k) = get_tuple()
	while k > 0:
		if n % 2 == 0:
			break
		n += smallest(n)
		k -= 1
	n += 2 * k
	print(n)
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


t = int(input())
for asd in range(t):
	a = [int(x) for x in input().split()]
	n = a[0]
	k = a[1]
	if n % 2 == 0:
		print(n + k * 2)
	else:
		val = 0
		for i in range(3, n + 1):
			if n % i == 0:
				val = i
				break
		n = n + val
		print(n + (k - 1) * 2)


def f(n):
	for d in range(2, int(n ** 0.5) + 1):
		if n % d == 0:
			return d
	return n

def solve(n, k):
	count = 0
	prev = None
	while count < k:
		count += 1
		res = f(n)
		n += res
		if res == 2:
			return n + 2 * (k - count)
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(solve(n, k))


import math

def orac_and_factor(n, k):
	result = n
	if n == 1:
		return 1
	start = 2
	if n % 2 != 0:
		start = 3
	for i in range(start, math.ceil(math.sqrt(n)) + 1, 2):
		if n % i == 0:
			result += i
			break
	if result == n:
		result += n
		n = result
	return result + 2 * (k - 1)
n = int(input())
for i in range(n):
	line1 = map(lambda x: int(x), input().strip().split())
	print(orac_and_factor(*line1))


import math
for _ in range(int(input())):
	(n, am) = list(map(int, input().split()))
	need = 0
	for i in range(2, math.ceil(n / 2) + 1):
		if n % i == 0:
			need = i
			break
	else:
		need = n
	print(n + need + (am - 1) * 2)


def sd(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 0
	if n % 2 == 0:
		ans = n + k * 2
	else:
		val = sd(n)
		ans = n + val + (k - 1) * 2
	print(ans)


t = int(input())
while t:
	(a, b) = map(int, input().split())
	if a % 2 == 0:
		print(a + b * 2)
	else:
		v = 0
		for i in range(2, a + 1):
			if a % i == 0:
				v = i
				break
		print(a + v + (b - 1) * 2)
	t -= 1


from math import sqrt
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	factor = 2
	maxFactor = sqrt(n)
	while factor <= maxFactor:
		if n % factor == 0:
			break
		factor += 1
	if n % factor != 0:
		factor = n
	res = n + factor + (k - 1) * 2
	print(res)


import math

def ans(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = int(input())
f = 0
while t > 0:
	sum = 0
	(a, b) = map(int, input().split())
	sum = a
	if a % 2 == 0:
		sum += 2 * b
		print(sum)
	else:
		sum = a + ans(a)
		sum += (b - 1) * 2
		print(sum)
	t -= 1


tc = int(input())
for i in range(tc):
	(n, k) = [int(x) for x in input().split()]
	if n % 2 == 0:
		print(n + k * 2)
	else:
		d = 3
		while d <= n:
			if n % d == 0:
				break
			d += 2
		print(n + d + (k - 1) * 2)


from math import sqrt
y = int(input())
ans = []
for i in range(y):
	al = input().split()
	m = list(map(int, al))
	n = m[0]
	k = m[1]
	s = 3
	sq = int(sqrt(n)) + 1
	if n % 2 == 0:
		s = 2
	while n % s != 0 and s <= sq:
		s += 2
	if n % s != 0:
		s = n
		if k == 1:
			ans.append(2 * n)
			continue
		else:
			ans.append(2 * (n + k - 1))
			continue
	if s == 2:
		ans.append(2 * (int(n / 2) + k))
	elif s > 2:
		b = n / s
		new = s * (b + 1)
		s = 2
		b = int(new / s)
		ans.append(2 * (b + k - 1))
for i in ans:
	print(i)


def f(n, k):
	d = 0
	c = 0
	for i in range(2, int(n ** (1 / 2) + +2)):
		if n % i == 0:
			c = i
			d = 1
			break
	if n % 2 != 0 and d == 0:
		return 2 * n + 2 * (k - 1)
	elif n % 2 != 0 or d == 1:
		return n + c + 2 * (k - 1)
T = int(input())
while T > 0:
	(n, k) = map(int, input().split())
	print(f(n, k))
	T -= 1


from math import sqrt

def find_factor(num):
	end = int(sqrt(num)) + 1
	ans = 0
	for i in range(3, end, 2):
		if num % i == 0:
			ans = i
			break
	if ans == 0:
		ans = num
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		final_ans = n + k * 2
	else:
		final_ans = n + find_factor(n)
		final_ans += (k - 1) * 2
	print(final_ans)


T = int(input())
while T > 0:
	(n, k) = map(int, input().split())
	flag = False
	if n % 2 == 0:
		n += 2 * k
	else:
		for i in range(3, int(n / 2), 2):
			if n % i == 0:
				n += i
				flag = True
				break
		if flag == False:
			n += n
		n += 2 * (k - 1)
	print(n)
	T -= 1


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
for _ in range(ii()):
	(n, k) = mi()
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + sorted(divs(n))[1] + 2 * (k - 1))


import sys, random
from bisect import bisect_left, bisect_right
input = sys.stdin.readline

def main():
	inf = 10 ** 20
	t = int(input())
	isnt_prime = [0] * 1000005
	prime = []
	for i in range(2, 1000005):
		if not isnt_prime[i]:
			prime.append(i)
			for j in range(i + i, 1000005, i):
				isnt_prime[j] = 1
	for _ in range(1, t + 1):
		(n, k) = map(int, input().split())
		for x in prime:
			if not n % x:
				n += x
				break
		print(n + 2 * (k - 1))
main()


t = int(input())
for tt in range(t):
	(n, k) = [int(x) for x in input().split(' ')]
	if n % 2 == 0:
		print(round(n + k * 2))
	else:
		p = 0
		for t in range(2, n + 1):
			if n % t == 0:
				p = t
				break
		print(round(n + p + (k - 1) * 2))


import sys
for t in range(int(sys.stdin.readline())):
	(n, k) = map(int, sys.stdin.readline().split())
	if n & 1:
		for i in range(3, int(n ** 0.5 + 2)):
			if not n % i:
				n += i
				k -= 1
				break
		else:
			sys.stdout.write('{}\n'.format(n * 2 + 2 * (k - 1)))
			continue
		sys.stdout.write('{}\n'.format(n + k * 2))
	else:
		sys.stdout.write('{}\n'.format(n + k * 2))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
testcases = int(input())
for j in range(testcases):
	vals = list(map(int, input().split()))
	n = vals[0]
	k = vals[1]
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		broke = False
		endval = n
		for s in range(3, math.ceil(math.sqrt(n)) + 1):
			if n % s == 0:
				endval += s
				broke = True
				break
		if broke == False:
			endval += n
		endval += (k - 1) * 2
		print(endval)


x = int(input())
for i in range(x):
	l = []
	(a, b) = list(map(int, input().split()))
	for j in range(1, a + 1):
		if a % j == 0:
			l.append(j)
	if a % 2 == 0:
		print(a + 2 * b)
	else:
		print(a + 2 * (b - 1) + l[1])


from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())
for _ in range(gete(int)):
	(n, k) = geta(int)
	if n & 1 == 0:
		print(n + k * 2)
	else:
		d = 3
		ok = False
		while d * d <= n:
			if n % d == 0:
				ok = True
				break
			d += 2
		if not ok:
			d = n
		print(n + d + 2 * (k - 1))


def main():
	t = int(input())
	ns = []
	ks = []
	for _ in range(t):
		(n, k) = [int(ch) for ch in input().split(' ')]
		ns.append(n)
		ks.append(k)
	for (n, k) in zip(ns, ks):
		if n % 2 == 0:
			print(n + 2 * k)
		else:
			for i in range(2, n + 1):
				if n % i == 0:
					div = i
					break
			n += div
			print(n + 2 * (k - 1))
main()


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby

def Golf():
	(*a,) = map(int, open(0))

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def bit_combination(n, base=2):
	rt = []
	for tb in range(base ** n):
		s = [tb // base ** bt % base for bt in range(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['YES', 'NO']
Yn = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(1, 0), (-1, 0), (0, 1), (0, -1)]
EightNb = [(1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('EWNS', FourNb))
l_alp = string.ascii_lowercase
input = lambda : sys.stdin.readline().rstrip()

class Tree:

	def __init__(self, inp_size=None, ls=None, init=True, index=0):
		self.LCA_init_stat = False
		self.ETtable = []
		if init:
			if ls == None:
				self.stdin(inp_size, index=index)
			else:
				self.size = len(ls) + 1
				(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def stdin(self, inp_size=None, index=1):
		if inp_size == None:
			self.size = int(input())
		else:
			self.size = inp_size
		(self.edges, _) = GI(self.size, self.size - 1, index=index)
		return

	def listin(self, ls, index=0):
		self.size = len(ls) + 1
		(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def __str__(self):
		return str(self.edges)

	def dfs(self, x, func=lambda prv, nx, dist: prv + dist, root_v=0):
		q = deque()
		q.append(x)
		v = [-1] * self.size
		v[x] = root_v
		while q:
			c = q.pop()
			for (nb, d) in self.edges[c]:
				if v[nb] == -1:
					q.append(nb)
					v[nb] = func(v[c], nb, d)
		return v

	def EulerTour(self, x):
		q = deque()
		q.append(x)
		self.depth = [None] * self.size
		self.depth[x] = 0
		self.ETtable = []
		self.ETdepth = []
		self.ETin = [-1] * self.size
		self.ETout = [-1] * self.size
		cnt = 0
		while q:
			c = q.pop()
			if c < 0:
				ce = ~c
			else:
				ce = c
				for (nb, d) in self.edges[ce]:
					if self.depth[nb] == None:
						q.append(~ce)
						q.append(nb)
						self.depth[nb] = self.depth[ce] + 1
			self.ETtable.append(ce)
			self.ETdepth.append(self.depth[ce])
			if self.ETin[ce] == -1:
				self.ETin[ce] = cnt
			else:
				self.ETout[ce] = cnt
			cnt += 1
		return

	def LCA_init(self, root):
		self.EulerTour(root)
		self.st = SparseTable(self.ETdepth, init_func=min, init_idl=inf)
		self.LCA_init_stat = True
		return

	def LCA(self, root, x, y):
		if self.LCA_init_stat == False:
			self.LCA_init(root)
		(xin, xout) = (self.ETin[x], self.ETout[x])
		(yin, yout) = (self.ETin[y], self.ETout[y])
		a = min(xin, yin)
		b = max(xout, yout, xin, yin)
		id_of_min_dep_in_et = self.st.query_id(a, b + 1)
		return self.ETtable[id_of_min_dep_in_et]

class SparseTable:

	def __init__(self, ls, init_func=min, init_idl=float('inf')):
		self.func = init_func
		self.idl = init_idl
		self.size = len(ls)
		self.N0 = self.size.bit_length()
		self.table = [ls[:]]
		self.index = [list(range(self.size))]
		self.lg = [0] * (self.size + 1)
		for i in range(2, self.size + 1):
			self.lg[i] = self.lg[i >> 1] + 1
		for i in range(self.N0):
			tmp = [self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) for j in range(self.size)]
			tmp_id = [self.index[i][j] if self.table[i][j] == self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) else self.index[i][min(j + (1 << i), self.size - 1)] for j in range(self.size)]
			self.table += [tmp]
			self.index += [tmp_id]

	def query(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		return self.func(self.table[N][l], self.table[N][r - (1 << N)])

	def query_id(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		(a, b) = (self.index[N][l], self.index[N][r - (1 << N)])
		if self.table[0][a] == self.func(self.table[N][l], self.table[N][r - (1 << N)]):
			b = a
		return b

	def __str__(self):
		return str(self.table[0])

	def print(self):
		for i in self.table:
			print(*i)

class Comb:

	def __init__(self, n, mo=10 ** 9 + 7):
		self.fac = [0] * (n + 1)
		self.inv = [1] * (n + 1)
		self.fac[0] = 1
		self.fact(n)
		for i in range(1, n + 1):
			self.fac[i] = i * self.fac[i - 1] % mo
			self.inv[n] *= i
			self.inv[n] %= mo
		self.inv[n] = pow(self.inv[n], mo - 2, mo)
		for i in range(1, n):
			self.inv[n - i] = self.inv[n - i + 1] * (n - i + 1) % mo
		return

	def fact(self, n):
		return self.fac[n]

	def invf(self, n):
		return self.inv[n]

	def comb(self, x, y):
		if y < 0 or y > x:
			return 0
		return self.fac[x] * self.inv[x - y] * self.inv[y] % mo
show_flg = False
show_flg = True
ans = 0
T = I()

def f(n):
	for i in range(2, int(n ** 0.5) + 10):
		if n % i == 0:
			return i
	return n
for _ in range(T):
	ans = 0
	(n, k) = LI()
	n = n + f(n)
	k -= 1
	ans = n + 2 * k
	print(ans)


import math
t = int(input())

def smallest_divisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def f(n, k):
	for i in range(k):
		n = n + smallest_divisor(n)
		if n % 2 == 0:
			break
	n = 2 * (k - i - 1) + n
	return n
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	ans = f(n, k)
	print(ans)


a = int(input())
import math

def fact(x):
	ans = []
	for i in range(1, int(math.sqrt(x)) + 1):
		if x % i == 0:
			if i == x // i:
				ans.append(i)
			else:
				ans.append(x // i)
				ans.append(i)
	ans.sort()
	return ans
for i in range(a):
	(n, k) = map(int, input().split())
	ans = n
	fac = fact(n)
	if fac[1] == n:
		ans = 2 * n
		k = k - 1
		fac[1] = 2
	if k == 0:
		print(ans)
		continue
	if fac[1] == 2:
		ans = ans + k * 2
		print(ans)
		continue
	else:
		ans = ans + fac[1]
		k = k - 1
		if k == 0:
			print(ans)
			continue
		else:
			k = k
			ans = ans + k * 2
			print(ans)
			continue


inp = input
li = list
iinp = lambda : int(inp())
ent = lambda : map(int, inp().split())
lient = lambda : [int(i) for i in inp().split()]
li0 = lambda x: [0 for i in range(x)]
livalor = lambda valor, x: [valor for i in range(x)]
stent = lambda : [i for i in inp()]
filldp = lambda valor, x, y: [[valor for i in range(y)] for i in range(x)]
from math import sqrt as sq
from math import ceil as c

def primo(n):
	if n <= 2:
		return [True]
	medio = c(sq(n)) + 1
	for i in range(2, medio):
		if n % i == 0:
			return [False, i]
	return [True]
t = iinp()
for _ in range(t):
	(n, k) = ent()
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		tmp = primo(n)
		if tmp[0]:
			print(n + n + 2 * (k - 1))
		else:
			res = n + tmp[1]
			print(res + 2 * (k - 1))


import random
import math
import sys
LI = lambda : list(map(int, input().split()))
MI = lambda : map(int, input().split())
yes = lambda : print('Yes')
no = lambda : print('No')
I = lambda : list(input())
J = lambda x: ''.join(x)
II = lambda : int(input())
SI = lambda : input()
t = II()
for q in range(t):
	(n, k) = MI()
	boo = True
	a = 0
	ans = n
	while a != 2 and k > 0:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				a = i
				boo = False
				break
		if boo == False:
			ans += a
			n += a
		else:
			ans += n
			n += n
		k -= 1
		if a == 2:
			ans += 2 * k
			break
	print(ans)


from sys import stdin, stdout
import math

def main():
	t = int(stdin.readline())
	for _ in range(t):
		(n, k) = map(int, input().split())
		counter = 0
		if n % 2 == 0:
			n = n + 2
			ren = k - 1
			n = n + ren * 2
			print(n)
		else:
			fact = 0
			for i in range(2, int(math.sqrt(n) + 1)):
				if n % i == 0:
					counter = 1
					fact = i
					break
			if counter == 0:
				n += n
				ren = k - 1
				n = n + 2 * ren
				print(n)
			else:
				n = n + fact
				ren = k - 1
				n = n + ren * 2
				print(n)
main()


import math

def sol(x):
	(n, k) = (int(x[0]), int(x[1]))
	temp = math.sqrt(n)
	index = 2
	while n % index != 0 and index < temp:
		index += 1
	if n % index != 0 and index > temp:
		n *= 2
	else:
		n += index
	n += 2 * (k - 1)
	return n

def main():
	t = int(input())
	for g in range(t):
		x = input().split()
		print(sol(x))
main()


import math

def solve():
	(n, k) = list(map(int, input().split(' ')))
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		if n % i == 0:
			n += i
			break
	else:
		n += n
	n += 2 * (k - 1)
	print(n)
T = int(input())
for i in range(T):
	solve()


from sys import stdin
import math
a = int(stdin.readline())
for b in range(0, a):
	c = stdin.readline().split()
	n = int(c[0])
	k = int(c[1])
	ans = n
	if n % 2 == 1:
		factor = 2
		while n % factor != 0:
			factor += 1
		ans += factor
		print(ans + (k - 1) * 2)
	if n % 2 == 0:
		print(n + 2 * k)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	for j in range(k):
		d = 0
		if n % 2 == 0:
			print(n + 2 * (k - j))
			d = 1
			break
		else:
			l = 2
			p = 0
			while l * l <= n:
				if n % l == 0:
					n += l
					p = 1
					break
				l += 1
			if p == 0:
				n *= 2
	if d == 0:
		print(n)


import math

def func(num):
	i = 2
	while i <= math.floor(math.sqrt(num)) and num % i != 0:
		i += 1
	if i >= math.floor(math.sqrt(num)) and num % i != 0:
		return num
	else:
		return i
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + 2 * (k - 1) + func(n))


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	c = 0
	for i in range(2, a + 1):
		if a % i == 0:
			c = i
			break
	c = c + a
	if c % 2 == 0:
		c = c + 2 * (b - 1)
	else:
		c = c + a * b
	print(c)


import sys
import bisect
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(int(ri())):
	(n, k) = Ri()
	p = 2
	flag = False
	ans = 0
	while p * p <= n:
		if n % p == 0:
			flag = True
			break
		p += 1
	if p == 2 and flag == True:
		ans = n + 2 * k
	elif not flag:
		ans = n + n
		k -= 1
		if k > 0:
			ans += 2 * k
	elif flag:
		ans = n + p
		k -= 1
		if k > 0:
			ans += 2 * k
	print(ans)


p = int(input())
for i in range(p):
	result = 0
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		result = n + 2
		result += (k - 1) * 2
	else:
		c = 3
		while n % c != 0:
			c += 1
		result = c + n + (k - 1) * 2
	print(result)


for t in range(int(input())):
	(n, k) = [int(j) for j in input().split()]
	tmp = 0
	for i in range(2, int(n ** 0.5) + 3):
		if n % i == 0:
			tmp = i
			break
	if tmp == 0:
		tmp = n
	tmp2 = 0
	while tmp2 != tmp:
		k -= 1
		if tmp2 != 0:
			tmp = tmp2
		n = n + tmp
		for i in range(2, tmp + 1):
			if n % i == 0:
				tmp2 = i
				break
	print(n + tmp * k)


import math

def f(x):
	x = int(x)
	if x < 4:
		return x
	for i in range(2, int(math.sqrt(x)) + 1):
		if x % i == 0:
			break
	else:
		return x
	return i

def run(n, k):
	(n, k) = (int(n), int(k))
	if k == 1:
		return f(n) + n
	for x in range(1, k + 1):
		if n % 2 != 0:
			n = f(n) + n
		else:
			break
	n = (k + 1 - x) * 2 + n
	return n
sets = input()
list = []
for z in range(int(sets)):
	(n, k) = input().split()
	list.append(run(n, k))
for result in list:
	print(result)


def divisor(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	print(divisor(n) + (k - 1) * 2 + n)


MOD = 1000000007

def fact(n):
	if n & 1:
		for i in range(3, n + 1):
			if n % i == 0:
				return i
	else:
		return 2

def solve(n, k):
	f = fact(n)
	ans = 0
	if n & 1:
		ans = f + n + 2 * (k - 1)
	else:
		ans = n + 2 * k
	print(ans)
for i in range(int(input())):
	(n, k) = map(int, input().split())
	solve(n, k)


def sieve(n):
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
prime = [True for i in range(1000000 + 1)]
sieve(1000000)
pri = []
for i in range(2, 1000001):
	if prime[i]:
		pri.append(i)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		c = 0
		for i in pri:
			if n % i == 0:
				c = i
				break
		print(n + c + 2 * (k - 1))


import itertools as it
is_plain = [True] * 1001
is_plain[:2] = (False, False)
for i in range(1001):
	if not is_plain[i]:
		continue
	for j in range(2 * i, 1001, i):
		is_plain[j] = False
plain = list(it.compress(range(1001), is_plain))
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 1:
		div = n
		for p in plain:
			if n % p == 0:
				div = p
				break
		n += div
		k -= 1
	n += 2 * k
	print(n)


import sys
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def read():
	tc = 0
	if tc:
		input = sys.stdin.readline
	else:
		sys.stdin = open('input1.txt', 'r')
		sys.stdout = open('output1.txt', 'w')

def isprime(n):
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return 0
	return 1

def fact():
	n = 2
	while len(p) <= 200:
		if isprime(n):
			p.append(n)
		n += 1

def solve():
	for _ in range(ii()):
		(n, k) = mi()
		for i in range(k):
			c = -1
			for j in range(2, int(sqrt(n)) + 1):
				if n % j == 0:
					f = 1
					c = j
					break
			if c == -1:
				c = n
			if c == 2:
				n += 2 * (k - i)
				break
			else:
				n += c
		print(n)
solve()


from math import sqrt

def mind(x):
	for i in range(2, int(sqrt(x)) + 1):
		if x % i == 0:
			return i
	return x
q = int(input())
for i in range(q):
	(n, k) = map(int, input().split())
	t = mind(n)
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + t + 2 * (k - 1))


import io
import os

def solve(N, K):
	for divisor in range(2, N + 1):
		if N % divisor == 0:
			N += divisor
			K -= 1
			if N % 2 == 0:
				N += 2 * K
				K = 0
			if K == 0:
				return N
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N, K) = [int(x) for x in input().split()]
	ans = solve(N, K)
	print(ans)


def foo(x):
	z = int(x ** (1 / 2))
	c = x
	for i in range(2, z + 1):
		if x % i == 0:
			c = i
			break
	return c
for t in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		d = foo(n)
		print(n + 2 * (k - 1) + d)


def div(n):
	for j in range(2, n + 1):
		if n % j == 0:
			n = n + j
			break
	return n
p = []
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(2 * k + n)
	else:
		for j in range(k):
			if len(p) == 0:
				if div(n) % 2 == 0:
					print(div(n) + 2 * (k - j - 1))
					break
				else:
					p.append(div(n))
			elif div(p[-1]) % 2 == 0:
				print(div(p[-1]) + 2 * (k - j - 1))
				break
			else:
				p.append(div(p[-1]))
		p.clear()


import math
import sys
input = sys.stdin.readline
output = sys.stdout

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def solve(n, k):
	num = n
	for j in range(k):
		for i in range(2, math.ceil(math.sqrt(n)) + 1):
			if n % i == 0:
				n += i
				break
		if n == num:
			n = n * 2
		if n % 2 == 0:
			imp = k - 1
			break
	n += imp * 2
	output.write(str(n) + '\n')
n = inp()
for i in range(n):
	l = inlt()
	solve(l[0], l[1])


t = int(input())
for test in range(t):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	smallest = 10 ** 9
	for i in range(2, n + 1):
		if n % i == 0:
			smallest = i
			break
	n = n + smallest
	k -= 1
	smallest = 2
	n = n + k * 2
	print(n)


def cal(n, count):
	if n % 2 == 0:
		return 2
	p = 3
	while p * p <= n and p <= count:
		if n % p == 0:
			return p
		p += 2
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	val = cal(n, n // 2)
	n = n + val
	n = n + 2 * (k - 1)
	print(n)


def f(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
	return None
tests = int(input())
for _ in range(tests):
	splits = input().split(' ')
	n = int(splits[0])
	k = int(splits[1])
	while k > 0 and n % 2 != 0:
		n += f(n)
		k -= 1
	print(n + 2 * k)


def SieveOfEratosthenes(n):
	p1 = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			p1.append(p)
	return p1
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	c = 1
	list_of_primes = SieveOfEratosthenes(n)
	for i in list_of_primes:
		if n % i == 0:
			c = i
			break
	print((k - 1) * 2 + c + n)


def oddfactor(n):
	i = 3
	while n % i != 0:
		i += 2
	return i
t = int(input())
for case in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		a = oddfactor(n)
		print(n + a + 2 * (k - 1))


n1 = int(input())
for _ in range(0, n1):
	l = list(map(int, input().split()))
	n = l[0]
	min = 0
	t = 3
	count = 0
	while t * t <= n and n % t:
		t = t + 2
	if n % 2 == 0:
		min = 2
	elif t * t > n:
		min = n
	elif n % t == 0:
		min = t
	n = min + n
	if n % 2 == 0:
		print(n + (l[1] - 1) * 2)
	else:
		print(n + (l[1] - 1) * 2)


cases = int(input())
for i in range(cases):
	(n, k) = [int(p) for p in input().split()]
	divs = 0
	if n % 2 == 0:
		print(n + k * 2)
	else:
		for j in range(3, 1001):
			if n % j == 0:
				divs += 1
				n = n + j
				break
		if divs > 0:
			print(n + (k - 1) * 2)
		else:
			print(2 * n + (k - 1) * 2)


def divisor(n):
	ass = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			ass.append(i)
			ass.append(n // i)
	return sorted(ass)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		l = divisor(n)
		ll = l[1]
		print(n + ll + 2 * (k - 1))


def prime(n):
	if n % 2 == 0:
		return 2
	m = int(n ** 0.5) + 1
	for i in range(3, m, 2):
		if n % i == 0:
			return i
	return n

def fun(n, k):
	ans = n + prime(n)
	count = 1
	while ans % 2 != 0 and count < k:
		ans = ans + prime(ans)
		count += 1
	if k - count > 0:
		ans += 2 * (k - count)
	return ans
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print(fun(n, k))


t = int(input())
while t > 0:
	t -= 1
	inp = input().split(' ')
	n = int(inp[0])
	k = int(inp[1])
	while k > 0:
		if n % 2 == 0:
			n += 2 * k
			break
		else:
			for i in range(3, n + 1):
				if n % i == 0:
					n += i
					break
		k -= 1
	print(n)


import sys
input = sys.stdin.readline

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors

def main():
	t = int(input())
	for _ in range(t):
		(N, K) = [int(x) for x in input().split()]
		if N % 2 == 0:
			print(N + 2 * K)
		else:
			x = make_divisors(N)
			print(N + 2 * (K - 1) + x[1])
main()


import sys
import math
from collections import defaultdict

def solve(test):
	(n, k) = map(int, input().split())
	if n & 1:
		res = None
		for i in range(3, int(math.sqrt(n)) + 1, 2):
			if n % i == 0:
				res = i
				break
		res = (n if res is None else res) + n
		res += 2 * (k - 1)
		print(res)
	else:
		print(n + 2 * k)
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


import math

def divisor(n):
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return i
	return n

def answer(n, k):
	if n % 2 == 0:
		return n + 2 * k
	else:
		x = divisor(n)
		return x + n + 2 * (k - 1)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print(answer(n, k))


for ttt in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		x = -1
		for i in range(2, int(n ** 0.5 + 10)):
			if n % i == 0:
				x = i
				break
		if x == -1:
			x = n
		print(n + x + 2 * (k - 1))


from math import sqrt

def min_factor(n):
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return i
	return n

def solve(n, k):
	if n % 2 != 0:
		k -= 1
		n += min_factor(n)
	n += 2 * k
	return n
for i in range(int(input())):
	(n, k) = map(int, input().split())
	print(solve(n, k))


t = int(input())
for ii in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		f = 0
		for j in range(2, n + 1):
			if n % j == 0:
				print(n + j + 2 * (k - 1))
				break


from collections import defaultdict
cache = defaultdict(int)

def get_smallest_devisor(n):
	i = 3
	while i * i <= n:
		if n % i == 0:
			cache[n] = i
			return i
		i += 2
	cache[n] = n
	return n
for t in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	if n % 2 == 0:
		print(n + k * 2)
	else:
		d = cache[n]
		if d == 0:
			d = get_smallest_devisor(n)
		print(n + d + (k - 1) * 2)


def inp():
	return int(input())

def insr():
	s = input()
	return s

def inlt():
	return list(map(int, input().split()))

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
r = inp()
for i in range(r):
	inp1 = inlt()
	number = inp1[0]
	times = inp1[1]
	if number % 2 == 0:
		print(number + 2 * times)
		continue
	print(number + smallestDivisor(number) + 2 * (times - 1))


def find_sec(num):
	tmp = int(num ** 0.5 + 0.5)
	for i in range(2, tmp + 1):
		if num % i == 0:
			return i
	return num
all = int(input())
answer = []
for i in range(all):
	n_k = input()
	n = int(n_k.split(' ')[0])
	k = int(n_k.split(' ')[1])
	if n % 2 == 0:
		answer.append(n + 2 * k)
	else:
		answer.append(n + find_sec(n) + (k - 1) * 2)
for ans in answer:
	print(ans)


def f(n):
	if n % 2 == 0:
		return n + 2
	else:
		for j in range(3, n + 1, 2):
			if n % j == 0:
				return n + j

def main():
	t = int(input())
	for i in range(t):
		(n, k) = map(int, input().split())
		j = 0
		while j < k and n % 2 == 1:
			n = f(n)
			j += 1
		n += 2 * (k - j)
		print(n)
main()


for _ in range(int(input())):
	nk = list(map(int, input().rstrip().rsplit()))
	(n, k) = (nk[0], nk[1])
	for i in range(2, n + 1):
		if n % i == 0:
			d = i
			break
	ans = n + d + 2 * (k - 1)
	print(ans)


from math import sqrt, floor
prime = [0] * 1000001
for i in range(2, floor(sqrt(1000000)) + 1):
	if prime[i] != 0:
		continue
	for j in range(i * i, 1000001, i):
		if prime[j] == 0:
			prime[j] = i
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if prime[n] == 0:
		prime[n] = n
	print(n + prime[n] + (k - 1) * 2)


import math

def isPrime(n):
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def minPrimeDiv(n):
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0 and isPrime(i):
			return i
	return n

def solve(n, k):
	while k != 0:
		if minPrimeDiv(n) == 2:
			return n + k * minPrimeDiv(n)
		else:
			n += minPrimeDiv(n)
			k -= 1
	return n
test_cases = int(input())
for _ in range(test_cases):
	(n, k) = list(map(int, input().split()))
	print(solve(n, k))


def OracAndfactors(n, k):
	i = 2
	while n % i != 0:
		i += 1
	return n + i + (k - 1) * 2
for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	print(OracAndfactors(n, k))


def smalldiv(n):
	i = 2
	while i <= n ** 0.5:
		if n % i == 0:
			return i
		i += 1
	return n
t = int(input())
while t:
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + smalldiv(n) + (k - 1) * 2)
	t -= 1


def find_smallest_divisor(n):
	for i in range(2, n + 1, 1):
		if n % i == 0:
			return i

def solve(n, k):
	if n % 2 == 0:
		return n + k * 2
	else:
		val = find_smallest_divisor(n)
		return n + val + (k - 1) * 2
testCases = int(input())
while testCases:
	(N, K) = map(int, input().split())
	print(solve(N, K))
	testCases -= 1


from math import ceil, sqrt

def find_min_devider(n):
	for i in range(2, ceil(sqrt(n)) + 2):
		if n % i == 0:
			return i
	return n

def main():
	t = int(input())
	for i in range(t):
		(n, k) = map(int, input().split())
		if n % 2 == 0:
			print(n + k * 2)
		else:
			n += find_min_devider(n)
			n += (k - 1) * 2
			print(n)

def test():
	t = int(input())
	for i in range(t):
		print(find_min_devider(int(input())))
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
		continue
	divisor = 0
	for x in range(2, n + 1):
		if n % x == 0:
			divisor = x
			break
	print(n + 2 * (k - 1) + divisor)


def function(n):
	if n % 2 == 0:
		return 2
	elif n % 3 == 0:
		return 3
	i = 5
	while i * i <= n:
		if n % i == 0:
			return i
		elif n % (i + 2) == 0:
			return i + 2
		i += 6
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().strip().split())
	m = function(n)
	print(n + m + 2 * (k - 1))


import math
t = int(input().strip())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		j = 2
		while j <= math.sqrt(n) and n % j != 0:
			j += 1
		fn = j if j <= math.sqrt(n) else n
		print(n + fn + (k - 1) * 2)


import math
import os
import random
import re
import sys

def f(n):
	i = 2
	while i <= int(math.sqrt(n)):
		if n % i == 0:
			return i
		i += 1
	return n

def algo(n, k):
	a = f(n)
	if a % 2 == 0:
		return k * 2 + n
	else:
		return n + a + (k - 1) * 2
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(algo(n, k))


import sys
sys.setrecursionlimit(500000)
t = int(input())

def get_min_divisor(n: int):
	ret = n
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			ret = i
			break
	return ret

def f(n, k):
	if k == 0:
		return n
	d = get_min_divisor(n)
	if d % 2 == 0:
		return n + k * d
	else:
		return f(n + d, k - 1)
for _ in range(t):
	(n, k) = map(int, input().split())
	print(f(n, k))


def operate(num):
	div = num
	for i in range(2, int(num ** 0.5) + 1):
		if num % i == 0:
			div = i
			break
	return num + div
num_cases = int(input())
for case in range(num_cases):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	for i in range(k):
		div = n
		for j in range(2, int(n ** 0.5) + 1):
			if n % j == 0:
				div = j
				break
		if div == 2:
			n += 2 * (k - i)
			break
		else:
			n += div
	print(n)


def div(n):
	for i in range(3, n + 1):
		if n % i == 0:
			return i
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	while k:
		if n % 2 == 0:
			n += 2 * k
			break
		else:
			d = div(n)
			if not d:
				n *= 2
				if k > 1:
					n += 2 * (k - 1)
					break
			else:
				n += d
				if k > 1:
					n += 2 * (k - 1)
					break
		k -= 1
	print(n)


import math

def checkPrime(n):
	for i in range(3, n // 2 + 1):
		if n % i == 0:
			return i
	return n

def solve():
	(n, k) = list(map(int, input().split()))
	if n % 2 == 0:
		return k * 2 + n
	else:
		temp = checkPrime(n)
		n += temp
		return n + (k - 1) * 2
	return n
for i in range(int(input())):
	print(solve())


def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = int(input())
for tt in range(t):
	nk = input().split()
	n = int(nk[0])
	k = int(nk[1])
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		s = smallestDivisor(n)
		print(n + s + 2 * (k - 1))


import os
import sys
if os.path.exists('/mnt/c/Users/Square/square/codeforces'):
	f = iter(open('A.txt').readlines())

	def input():
		return next(f)
else:
	input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	r = 2
	while n % r != 0:
		r += 1
	k -= 1
	n += r
	n += 2 * k
	print(n)


def f(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
			break
for i in range(int(input())):
	(n, k) = map(int, input().split())
	index = 0
	for j in range(k):
		if n % 2 == 1:
			n += f(n)
			index += 1
		else:
			break
	if index != k:
		n += 2 * (k - index)
	print(n)


import math

def func(n):
	if n == 2:
		return 2
	firstDivisor = n
	for x in range(2, math.ceil(math.sqrt(n)) + 1):
		if n % x == 0:
			firstDivisor = x
			break
	return firstDivisor
t = int(input())
for x in range(1, t + 1):
	(n, k) = [int(x) for x in input().split(' ')]
	ret = n
	bop = False
	for x in range(k):
		j = func(ret)
		if ret % 2 == 0 and j % 2 == 0:
			bop = True
			print(ret + j * (k - x))
			break
		ret += func(ret)
	if not bop:
		print(ret)


t = int(input())
while t:
	t = t - 1
	(n, k) = map(int, input().split())
	cnt = n
	for i in range(2):
		k = k - 1
		cnt = n
		for i in range(2, int(n ** 0.5 + 1)):
			if n % i == 0:
				cnt = i
				break
		n = n + cnt
	n = n + cnt * k
	print(n)


import math

def func(n):
	i = 3
	if n % 2 == 0:
		return 2
	else:
		while i <= math.sqrt(n):
			if n % i == 0:
				return i
			else:
				i += 2
		return n
for t in range(int(input())):
	(n, k) = map(int, input().split())
	x = n + func(n)
	print(x + 2 * (k - 1))


for _ in [0] * int(input()):
	(n, k) = map(int, input().split())
	x = 2
	while x * x <= n:
		if n % x == 0:
			break
		x += 1
	if n % x:
		x = n
	print((k - 1) * 2 + n + x)


from math import *
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	p = sqrt(n)
	p = floor(p)
	p = p + 1
	for i in range(2, p + 2):
		y = n % i
		if y == 0:
			r = i
			break
	else:
		r = n
	if k == 1:
		a = r + n
	else:
		a = r + n
		a = a + (k - 1) * 2
	print(a)


for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	c = 2
	while n % c != 0:
		c += 1
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + 2 * (k - 1) + c)


def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
(t, i) = (int(input()), 0)
df = smallestDivisor
while i != t:
	i += 1
	(m, k) = map(int, input().split())
	while k != 0:
		x = df(m)
		if x % 2 == 0:
			m = m + x * k
			break
		else:
			m += x
		k -= 1
	print(m)


printn = lambda x: print(x, end='')
import sys
input = sys.stdin.readline
inn = lambda : int(input())
inl = lambda : list(map(int, input().split()))
inm = lambda : map(int, input().split())
ins = lambda : input().strip()
DBG = True
BIG = 10 ** 18
R = 10 ** 9 + 7

def ddprint(x):
	if DBG:
		print(x)

def f(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
t = inn()
for tt in range(t):
	(n, k) = inm()
	x = f(n)
	print(n + x + 2 * (k - 1))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())

	def divi(x):
		for i in range(2, n + 1):
			if x % i == 0:
				a = i
				break
		return a
	if n % 2 == 0:
		ans = n + 2 * k
	else:
		c = n + divi(n)
		ans = c + 2 * (k - 1)
	print(ans)


import math
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	first_div = n
	r = int(math.sqrt(n)) + 1
	for i in range(2, r):
		if n % i == 0:
			first_div = i
			break
	res = n + first_div
	k -= 1
	while k > 0:
		if first_div == 2:
			res += first_div * k
			break
		for j in range(first_div - 1, 1, -1):
			if res % j == 0:
				first_div = j
		res += first_div
		k -= 1
	print(res)


def f_of(n):
	i = 2
	j = 1
	if n % 2 != 0:
		i = 3
		j = 2
	while True:
		if n % i == 0:
			break
		elif i >= n / 2:
			i = n
			break
		i += j
	return i
testcase = int(input())
answer = []
while testcase != 0:
	n_k = input()
	n_k = n_k.split()
	n = int(n_k[0])
	k = int(n_k[1])
	while k != 0:
		sd = f_of(n)
		if sd == 2:
			n = n + k * 2
			break
		n = sd + n
		k -= 1
	answer.append(n)
	testcase -= 1
for i in answer:
	print(i)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a % 2 == 0:
		print(int(a + 2 * b))
	else:

		def smallestDivisor(n):
			i = 3
			while i * i <= n:
				if n % i == 0:
					return i
				i += 2
			return n
		k = smallestDivisor(a)
		print(int(a + k + 2 * (b - 1)))


t = int(input())
if 1 <= t <= 100:
	for i in range(t):
		(n, k) = list(map(int, input().split(' ')))
		if 2 <= n <= 1000000 and 1 <= k <= 1000000000:
			for i in range(k):
				if n % 2 == 0:
					n = n + 2 * (k - i)
					break
				else:
					p = 3
					while p <= n:
						if n % p == 0:
							n = n + p
							break
						p += 2
			print(n)


def func(n):
	for j in range(2, int(n ** 0.5) + 1):
		if n % j == 0:
			return j
			break
	return n
t = int(input())
for i in range(t):
	(N, k) = map(int, input().split())
	print(N + func(N) + 2 * (k - 1))


from math import sqrt

def f(n):
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return i
	return n
for t in range(int(input())):
	(n, k) = input().split(' ')
	(n, k) = (int(n), int(k))
	m = f(n)
	if m == 2:
		print(n + 2 * k)
	else:
		print(n + m + 2 * k - 2)


n = int(input())
for i in range(0, n):
	p = input().rstrip().split(' ')
	a = int(p[0])
	b = int(p[1])
	if a % 2 == 0:
		print(a + b * 2)
	elif b == 1:
		for j in range(3, 100000000, 2):
			if a % j == 0:
				print(a + j)
				break
	else:
		for j in range(3, 100000000000, 2):
			if a % j == 0:
				print(a + j + (b - 1) * 2)
				break


def firstDivisor(n):
	for i in range(2, n // 2 + 1):
		if n % i == 0:
			return i
	return n

def sol():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		ans = n + firstDivisor(n)
		if k > 1:
			ans += 2 * (k - 1)
		print(ans)
sol()


import math
t = int(input())
for u in range(t):
	(n, k) = list(map(int, input().split()))
	m = int(n)
	res = 0
	for i in range(1, math.ceil(math.sqrt(n)) + 1):
		if n % (i + 1) == 0:
			m = i + 1
			break
	res = n + m
	print(res + 2 * (k - 1))


import sys
for _ in range(int(sys.stdin.readline().rstrip())):
	(n, k) = list(map(int, sys.stdin.readline().rstrip().split()))
	re = n
	for i in range(2, n + 1):
		if n % i == 0:
			re = n + i + 2 * (k - 1)
			break
	print(re)


import math
t = int(input())
while t:
	(n, k) = [int(x) for x in input().split()]
	ans = n
	if n % 2 == 0:
		ans += k * 2
	else:
		flag = 0
		for i in range(2, math.floor(math.sqrt(n)) + 1):
			if n % i == 0:
				ans += i
				flag = 1
				break
		if flag == 0:
			ans += n
		ans += (k - 1) * 2
	print(ans)
	t -= 1


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	v = n
	for i in range(2, n + 1):
		if n % i == 0:
			v = v + i
			break
	v = v + 2 * (k - 1)
	print(v)


import math, sys
import heapq
from fractions import Fraction
from collections import Counter, defaultdict

def li():
	return list(map(int, sys.stdin.readline().split()))

def ls():
	return list(map(int, list(input())))

def la():
	return list(input())

def ii():
	return int(input())

def dic(x):
	return defaultdict(lambda : x)

def isPrime(n):
	i = 2
	if n == 1:
		return False
	while i <= int(math.sqrt(n)):
		if n % i == 0:
			return False
		i = i + 1
	return True

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def LCM(a, b):
	return a * b / gcd(a, b)
t = ii()
for _ in range(t):
	(n, k) = li()
	i = 2
	while i <= n:
		if n % i == 0:
			break
		i += 1
	print(n + i + (k - 1) * 2)


t = int(input())
for _ in range(0, t):
	(n, k) = map(int, input().split())
	if not n % 2:
		print(n + 2 * k)
	else:
		kk = 1
		for i in range(3, n + 1):
			if n % i == 0:
				kk = i
				break
		print(n + kk + 2 * (k - 1))


from math import *
from sys import stdin, stdout
input = stdin.buffer.readline
t = int(input())
while t > 0:
	(n, k) = [int(x) for x in input().split()]
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		x = -1
		for i in range(2, int(sqrt(n)) + 1):
			if n % i == 0:
				x = i
				break
		if x == -1:
			x = n
		if k == 1:
			print(n + x)
		else:
			print(n + x + 2 * (k - 1))
	t -= 1


t = int(input())
for _ in range(t):
	(n, k) = tuple([int(i) for i in input().split()])
	if n == 0:
		print(0)
		continue
	elif k == 0:
		print(n)
	elif n % 2 == 0:
		print(n + 2 * k)
		continue
	elif n == 1:
		print(n + 1 + (k - 1) * 2)
	else:
		fail = True
		for x in range(1, int(n ** 0.5 + 2) // 2):
			if n % (1 + 2 * x) == 0:
				print(n + 1 + 2 * x + (k - 1) * 2)
				fail = False
				break
		if fail:
			print(2 * n + (k - 1) * 2)


n = int(input())
import math
for xy in range(n):
	t = list(map(int, input().split()))
	if t[0] % 2 == 0:
		print(t[0] + 2 * t[1])
	else:
		k = True
		for xy in range(2, math.ceil(math.sqrt(t[0])) + 1):
			if t[0] % xy == 0:
				print(t[0] + xy + 2 * (t[1] - 1))
				k = False
				break
		if k:
			print(2 * t[0] + 2 * (t[1] - 1))


from sys import stdin, stdout
from os import path
if path.exists('input.txt'):
	stdin = open('input.txt', 'r')
	stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

	def S():
		return stdin.readline().rstrip()

	def Sn():
		return stdin.readline().split(' ')
from math import sqrt

def f(n):
	if n & 1 == 0:
		return 2
	lim = int(sqrt(n))
	for i in range(3, lim + 1):
		if n % i == 0:
			return i
	return n

def func(n, k):
	if n & 1 == 0:
		return n + 2 * k
	return n + 2 * (k - 1) + f(n)
st = ''
for _ in range(I()):
	(n, k) = In()
	ans = str(func(n, k))
	st = '\n'.join((st, ans))
print(st.lstrip())


import math

def min_div(n):
	cand = 2
	sqn = int(math.sqrt(n))
	while cand <= sqn:
		if n % cand == 0:
			return cand
		cand += 1
	return n
t = int(input())
for _ in range(t):
	spl = input().split(' ')
	n = int(spl[0])
	k = int(spl[1])
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + min_div(n) + 2 * (k - 1))


import sys
from math import sqrt, floor, factorial, gcd
inp = sys.stdin.readline
read = lambda : list(map(int, inp().strip().split()))

def min_div(n):
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return i
	return n

def a():
	ans = ''
	for _ in range(int(inp())):
		(n, k) = read()
		md = min_div(n)
		while md != 2:
			n += md
			md = min_div(n)
			k -= 1
		n += k * 2
		ans += str(n) + '\n'
	print(ans)
a()


def orac(n, k):
	if n % 2 == 0:
		return n + 2 * k
	else:
		for i in range(3, int(n ** 0.5) + 1, 2):
			if n % i == 0:
				return n + i + 2 * (k - 1)
		return 2 * n + 2 * (k - 1)
t = int(input())
for i in range(t):
	nk = input().split()
	n = int(nk[0])
	k = int(nk[1])
	print(orac(n, k))


import math

def f(n):
	result = n
	for s in range(2, n + 1):
		if n % s == 0:
			result = s
			break
	return result
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	count = k
	for i in range(k):
		if n & 1 == 0:
			res = 2 * k + n
			break
		else:
			n += f(n)
			count -= 1
			if n & 1 == 0:
				res = n + 2 * count
				break
	print(res)


x = int(input())
while 1 <= x:
	w = input()
	a = int(w.split()[0])
	b = int(w.split()[1])
	ans = 0
	for j in range(2, a + 1):
		if a % j == 0:
			ans = j
			break
	print(a + ans + 2 * (b - 1))
	x = x - 1


import math
t = int(input())
n_k = [list(map(int, input().split())) for _ in range(t)]

def divisor(n):
	if n % 2 == 0:
		n = 2
	else:
		i = 3
		m = math.sqrt(n)
		while i <= m:
			if n % i == 0:
				n = i
				break
			i += 2
	return n
for i in n_k:
	if i[0] % 2 == 0:
		print(i[0] + 2 * i[1])
	else:
		print(i[0] + 2 * (i[1] - 1) + divisor(i[0]))


def SD(n):
	c = 0
	a = 0
	for i in range(2, int(n ** 0.5) + 2):
		if n % i == 0:
			a = i
			c = 1
			break
	if c == 0:
		return n
	if c == 1:
		return a
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	x = n + SD(n)
	x = x + 2 * (k - 1)
	print(x)


def readInt():
	return int(input())

def readList():
	return list(map(int, input().rstrip().split()))

def readString():
	s = input()
	return s

def readInts():
	return map(int, input().rstrip().split())
memo = {}

def solve(n, k):
	while k > 0:
		if n % 2 == 0:
			n += 2 * k
			k = 0
		elif n in memo:
			n += memo[n]
			k -= 1
		else:
			for i in range(2, n + 1):
				if n % i == 0:
					memo[n] = i
					n += i
					k -= 1
					break
	return n
t = readInt()
for i in range(t):
	(n, k) = readInts()
	print(solve(n, k))


f = [1] * (10 ** 6 + 1)
f[0] = 0
f[1] = 0
d = []
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	bol = 1
	for i in range(2, int(n ** (1 / 2)) + 1):
		if n % i == 0:
			bol = 0
			tmp = i
			break
	if bol == 1:
		n += n
		n += 2 * (k - 1)
	else:
		n += tmp
		n += 2 * (k - 1)
	print(n)


def f(n):
	for i in range(2, round(n ** 0.5) + 1):
		if n % i == 0:
			return i
	return n
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	while n % 2 != 0 and k > 0:
		n = n + f(n)
		k -= 1
	n = n + 2 * k
	print(n)


def div(n):
	for i in range(3, n + 1):
		if n % i == 0:
			val = i
			break
	return val

def func(ip_ls):
	n = ip_ls[0]
	k = ip_ls[1]
	if n % 2 == 0:
		n = 2 * k + n
	elif n % 2 != 0:
		n = 2 * (k - 1) + div(n) + n
	return n
t = int(input())
op_ls = []
for i in range(t):
	ip_ls = list(map(int, input().split()))
	op_ls.append(func(ip_ls))
for i in op_ls:
	print(i)


cases = int(input())
for case in range(cases):
	values = input().split()
	(initial, times) = (int(values[0]), int(values[1]))
	counter = 0
	while counter < times:
		if initial % 2 == 0:
			initial += 2 * (times - counter)
			print(initial)
			break
		else:
			for number in range(3, initial + 1):
				if initial % number == 0:
					initial += number
					break
			counter += 1
			if counter == times:
				print(initial)


import math
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a % 2 == 0:
		print(a + 2 * b)
	else:
		c = 0
		for j in range(2, math.floor(math.sqrt(a)) + 1):
			if a % j == 0:
				k = j
				c = 1
				break
		if c == 0:
			k = a
		print(a + k + 2 * (b - 1))


t = int(input())
cache = {}
for i in range(t):
	inp = input().split()
	n = int(inp[0])
	k = int(inp[1])
	if n % 2 == 0:
		val = n + 2 * k
		print(val)
		continue
	i = 2
	while i * i <= n:
		if n % i == 0:
			n += i
			k -= 1
			break
		i += 1
	if i * i > n:
		n *= 2
		k -= 1
	val = n + 2 * k
	print(val)


n = int(input())

def Prime(n):
	if n & 1 == 0:
		return 2
	d = 3
	while d * d <= n:
		if n % d == 0:
			return d
		d = d + 2
	return 0
for _ in range(n):
	(a, b) = map(int, input().split())
	ans = a
	while b > 0:
		if ans % 2 == 0:
			ans += 2 * b
			b = 0
		elif Prime(ans) == 0:
			ans += a
			b -= 1
		else:
			j = 3
			while ans % j != 0:
				j += 1
			ans += j
			b -= 1
	print(ans)


import sys
import math

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = read_int()
for i in range(t):
	(n, k) = read_int_line()
	if n & 1 == 1:
		n = n + smallestDivisor(n)
		if k > 1:
			k -= 1
			n += 2 * k
	else:
		n = n + 2 * k
	print(n)


def f(n):
	for x in range(2, int(n ** 0.5 + 1)):
		if n % x == 0:
			return x
	return n

def sol(n, k):
	v = f(n) + n
	return print(v + (k - 1) * 2)
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	sol(n, k)


p = int(input())

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
while p > 0:
	p = p - 1
	na = input()
	n = list()
	n = na.split()
	for i in range(0, len(n)):
		n[i] = int(n[i])
	if n[0] % 2 == 0:
		print(n[0] + 2 * n[1])
	else:
		print(n[0] + 2 * (n[1] - 1) + smallestDivisor(n[0]))


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors
for _ in range(t):
	(n, k) = map(int, input().split())
	print(n + make_divisors(n)[1] + 2 * (k - 1))


import math

def fun(n):
	h = int(n ** 0.5) + 1
	i = 2
	while i < h:
		if n % i == 0:
			return i
		i += 1
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	elif k == 1:
		print(n + fun(n))
	else:
		n = n + fun(n)
		k -= 1
		print(n + k * 2)


from math import sqrt

def smallestDivisor(n):
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return i
	return n
for t in range(int(input())):
	(n, k) = map(int, input().split())
	s = smallestDivisor(n)
	print(n + s + (k - 1) * 2)


n = int(input())
q = []
for i in range(n):
	(a, k) = [int(v) for v in input().split()]
	lowest = 0
	for j in range(2, a + 1):
		if a % j == 0:
			lowest = j
			break
	a += lowest
	k -= 1
	a += 2 * k
	print(a)


from sys import stdin, stdout
t = stdin.readline

def f(x):
	for i in range(2, x + 1):
		if x % i == 0:
			return i
for i in range(int(t())):
	(n, k) = map(int, t().split())
	stdout.writelines('{}\n'.format(n + f(n) + 2 * (k - 1)))


MAX = int(1000000.0)

def small(n):
	for x in range(2, n + 1):
		if n % x == 0:
			return x
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = small(n)
	if k == 1:
		print(n + s)
	else:
		print(n + s + (k - 1) * 2)


def smallDivisor(n):
	i = 2
	while i <= n:
		if n % i == 0:
			break
		else:
			i = i + 1
	return i
t = int(input())
arr = []
for i in range(t):
	arr.append(list(map(int, input().split())))
for j in range(t):
	d = smallDivisor(arr[j][0])
	arr[j][0] = d + arr[j][0]
	if arr[j][1] > 1:
		print(2 * (arr[j][1] - 1) + arr[j][0])
	else:
		print(arr[j][0])


for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if n % 2 == 0:
		print(n + 2 * k)
		continue
	s = int(n ** 0.5)
	j = 0
	for i in range(2, s + 1):
		if n % i == 0:
			j = i
			break
	if j != 0:
		print(n + j + (k - 1) * 2)
	else:
		print(n + n + 2 * (k - 1))


import math
for _ in [0] * int(input()):
	(a, b) = map(int, input().split())

	def minDiv(x):
		flag = 0
		count = math.ceil(math.sqrt(x)) + 1
		for i in range(2, count):
			if x % i == 0:
				flag = 1
				return i
		if flag == 0:
			return x
	for i in range(0, b):
		if a % 2 == 0:
			a = a + (b - i) * 2
			break
		else:
			md = minDiv(a)
			a += md
	print(a)


import math
t = int(input())

def solve(n):
	sqr = math.floor(math.sqrt(n))
	for i in range(3, sqr + 1, 2):
		if n % i == 0:
			return i
	return n
while t:
	(n, k) = map(int, input().split())
	ans = 0
	if n % 2 == 0:
		ans = n + k * 2
	if n % 2 == 1:
		ans = n + 2 * (k - 1) + solve(n)
	print(ans)
	t -= 1


from math import *
for zz in range(int(input())):
	(n, k) = map(int, input().split())
	i = 2
	while i * i <= n:
		if n % i == 0:
			break
		i += 1
	if i * i > n:
		i = n
	print(n + i + 2 * (k - 1))


def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	cou = 0
	cou = smallestDivisor(n)
	if cou % 2:
		n += cou
		k -= 1
	else:
		n += 2
		k -= 1
	n += 2 * k
	print(n)


from math import *

def divi(n):
	if n % 2 == 0:
		return 2
	root = ceil(sqrt(n)) + 1
	for i in range(3, root, 2):
		if n % i == 0:
			return i
	return n

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		small = divi(n)
		n += small
		n += 2 * (k - 1)
		print(n)
main()


import math
(t, i) = (int(input()), 0)
for i in range(t):
	(z, j) = (0, 1)
	(m, k) = [int(j) for j in input().split(' ')]
	if m % 2 == 0:
		print(m + 2 * k)
	else:
		for l in range(2, int(math.sqrt(m) + 1)):
			if m % l == 0:
				z = l
				break
		else:
			z = m
		print(m + (k - 1) * 2 + z)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return map(int, input().split())

def array():
	return [int(i) for i in input().split()]
for _ in range(int(input())):
	(n, k) = value()
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		for i in range(3, n + 1):
			if n % i == 0:
				break
		print(n + 2 * (k - 1) + i)


import heapq as hp

def sd(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		ans = n
		if n % 2 == 0:
			ans += 2 * k
		elif isPrime(n):
			ans += n + 2 * (k - 1)
		else:
			ans += sd(n) + 2 * (k - 1)
		print(ans)
solve()


import math
t = int(input())
itog = []
for m in range(t):
	str = input()
	list = str.split()
	n = int(list[0])
	k = int(list[1])
	i = 2
	while i <= n:
		if n % i == 0:
			nok = i
			break
		i += 1
	n = n + nok + 2 * (k - 1)
	itog.append(n)
for i in range(t):
	print(itog[i])


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys

def sqr(n):
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return i
	return n
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	z = sqr(n)
	n += z + 2 * (k - 1)
	print(n)


import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
	(n, k) = nm()
	for i in range(2, n + 1):
		if n % i == 0:
			n += i
			break
	n += 2 * (k - 1)
	print(n)
	return
T = ni()
for _ in range(T):
	solve()


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0 and k == 1:
		print(2 + n)
	else:
		x = 0
		for i in range(2, n + 1):
			if n % i == 0:
				x = i
				break
		print(n + x + 2 * (k - 1))


def deler(x):
	ind = 2
	while x % ind != 0:
		ind += 1
	return ind
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print(n + deler(n) + 2 * (k - 1))


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def main():
	t = int(input())
	for i in range(t):
		(n, k) = [int(j) for j in input().split()]
		f = smallestDivisor(n)
		n = n + f
		n = n + 2 * (k - 1)
		print(n)
main()


def smallestfact(num):
	t = 2
	while num % t != 0:
		t += 1
		if t == num:
			return t
	return t
t = int(input())
for w in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + smallestfact(n) + (k - 1) * 2)


def f(n):
	c = 2
	for i in range(2, n + 1):
		if n % i == 0:
			c = i
			break
	return c

def solut(n, k):
	if n % 2 == 0:
		return n + k * 2
	else:
		return n + 2 * (k - 1) + f(n)
s = []
for i in range(int(input())):
	s.append(list(map(int, input().split())))
for i in range(len(s)):
	print(solut(int(s[i][0]), int(s[i][1])))


t = int(input())
while t != 0:
	result = 0
	(n, k) = list(map(int, input().split()))
	t = t - 1
	for j in range(k):
		if n % 2 == 0:
			n += (k - j) * 2
			break
		else:
			for i in range(3, n + 1, 2):
				if n % i == 0:
					n += i
					break
	print(n)


linp = 'list(map(int,input().split()))'
t = int(input())

def spf(num):
	for i in range(2, num + 1):
		if i * i > num:
			break
		if num % i == 0:
			return i
	return num
for T in range(t):
	(n, k) = eval(linp)
	s = spf(n)
	print(n + s + (k - 1) * 2)


t = int(input())
for q in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		d = 3
		while k > 0:
			if n % 2 == 0:
				n += k * 2
				break
			elif n % d == 0:
				n += d
				k -= 1
				d = 3
			else:
				d += 2
		print(n)


def orac_factors(n, k):
	divisor = find_divisor(n)
	n += divisor
	add = 2 * (k - 1)
	n += add
	print(n)

def find_divisor(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return i
	else:
		return n
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	orac_factors(n, k)


import math

def fac(n):
	if n % 2 == 0:
		return 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		if n % i == 0:
			return i
	return n
t = int(input())
for u in range(t):
	(n, k) = list(map(int, input().split()))
	f = 0
	if n % 2 == 0:
		n = n + k * 2
	else:
		f = fac(n)
		n = n + f + (k - 1) * 2
	print(n)


import math
for i in range(int(input())):
	(n, k) = map(int, input().split())
	g = math.floor(math.sqrt(n))
	if g == 1:
		n += n
		k = k - 1
	if n % 2 != 0:
		g = math.floor(math.sqrt(n))
		for j in range(2, g + 1):
			if n % j == 0:
				n += j
				k = k - 1
				break
			elif j == g:
				n += n
				k -= 1
	print(n + 2 * k)


from sys import stdin
from math import sqrt

def iinput():
	return int(stdin.readline())

def sinput():
	return input()

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))

def smallest_div(n):
	if n & 1 == 0:
		return 2
	for j in range(3, int(sqrt(n)) + 1, 2):
		if n % j == 0:
			return j
	return n
t = iinput()
while t:
	t -= 1
	(n, k) = minput()
	while k and n & 1:
		n += smallest_div(n)
		k -= 1
	n += 2 * k
	print(n)


t = int(input())
for q in range(t):
	[n, k] = [int(x) for x in input().split()]
	for w in range(k):
		if n % 2 == 0:
			f = 2 * (k - w)
			n = f + n
			break
		else:
			for i in range(3, n + 1, 2):
				if n % i == 0:
					f = i
					break
		n = f + n
	print(n)


from collections import Counter
t = int(input())
while t > 0:
	t = t - 1
	(n, k) = map(int, input().split())
	a = 0
	for i in range(2, n + 1):
		if n % i == 0:
			a = i
			break
	print(n + a + (k - 1) * 2)


for _ in [*open(0)][1:]:
	(n, k) = map(int, _.split())
	if n % 2:
		con = True
		for i in range(3, int(n ** 0.5) + 1, 2):
			if not n % i:
				d = i
				con = False
				break
		if con:
			d = n
		print(n + d + 2 * (k - 1))
	else:
		print(n + 2 * k)


import sys
content = sys.stdin.read().strip().splitlines()
content = content[1:]

def f(n):
	divisor = 0
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			divisor = i
			break
	if divisor == 0:
		divisor = n
	return divisor
for c in content:
	(n, k) = map(int, c.split())
	i = 0
	while i < k and n % 2 != 0:
		n = f(n) + n
		i += 1
	print(n + 2 * (k - i))


def divisors(M):
	import math
	d = []
	i = 1
	while math.sqrt(M) >= i:
		if M % i == 0:
			d.append(i)
			if i ** 2 != M:
				d.append(M // i)
		i = i + 1
	d.sort()
	return d
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	d = divisors(n)
	print(n + d[1] + 2 * (k - 1))


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
lambda i: int(stdin.readline())
lambda inp: map(int, stdin.readline().split())
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		ans = n + 2 * k
	else:
		for i in range(2, n + 1):
			if n % i == 0:
				ch = i
				break
		ans = ch + n
		k -= 1
		ans += 2 * k
	print(ans)


def main():
	for _ in range(int(input())):
		(n, k) = (int(x) for x in input().split())
		if n % 2:
			mn = n
			for j in range(3, int(n ** (1 / 2) + 1)):
				if n % j == 0:
					mn = j
					break
			print(mn + n + 2 * (k - 1))
		else:
			print(n + 2 * k)
	return 0
main()


import math

def isPrime(n):
	for i in range(2, int(math.sqrt(n)) + 5):
		if n % i == 0 and i != n:
			return i
	return -1
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	val = isPrime(n)
	if val == -1:
		n += n
		k -= 1
		n += k * 2
		print(n)
	else:
		n += val
		k -= 1
		n += k * 2
		print(n)


least_prime = [0] * 1000001
least_prime[1] = 1
for i in range(2, 1000001):
	if least_prime[i] == 0:
		least_prime[i] = i
		for j in range(2 * i, 1000001, i):
			if least_prime[j] == 0:
				least_prime[j] = i
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	while n % 2 != 0:
		n += least_prime[n]
		k -= 1
	n += k * 2
	print(n)


def f(l):
	(n, k) = l
	i = 2
	while n % i > 0:
		i += 1
	return n + i + (k - 1 << 1)
t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	print(f(l))


import sys
input = sys.stdin.readline
t = int(input())
for r in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		temp = 1
		for i in range(2, n + 1):
			if n % i == 0:
				temp = i
				break
		print(n + temp + (k - 1) * 2)


from sys import stdin
import math

def prime_factors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		return l
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			return l
			n = n / i
	if n > 2:
		l.append(n)
	return l
for _ in range(int(input())):
	(n, k) = map(int, stdin.readline().rstrip().split(' '))
	if n % 2:
		print(n + prime_factors(n)[0] + (k - 1) * 2)
	else:
		print(n + 2 * k)


def divisors(n):
	for j in range(3, n // 2, 2):
		if n % j == 0:
			return j
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		n *= 2
	elif n % 2 == 0:
		n += k * 2
	else:
		for i in range(1, k, 2):
			n += divisors(n)
			if n % 2 == 0:
				n += (k - i) * 2
				break
	print(n)


from collections import defaultdict
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	i = 2
	while i <= n:
		if n % i == 0:
			break
		i += 1
	sum = n + i + (k - 1) * 2
	print(sum)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n & 1 == 0:
		print(n + 2 * k)
		continue
	else:
		p = 2
		while p <= n:
			if n % p == 0:
				break
			p += 1
		n += p
		k -= 1
		print(n + 2 * k)
		continue


import sys
import math

def smallestdiv(x: int) -> int:
	cur = 2
	while cur <= round(math.sqrt(x)):
		if x % cur == 0:
			return cur
		cur += 1
	return x
t = int(sys.stdin.readline())
for i in range(t):
	(n, k) = [int(x) for x in sys.stdin.readline().split(' ')]
	SD = smallestdiv(n)
	n += SD
	n += (k - 1) * 2
	print(n)


from sys import stdin, stdout
import heapq
import cProfile, math
from collections import Counter, defaultdict, deque
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
import sys
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)
fac_warm_up = False
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n
		self.lista = [[_] for _ in range(n)]

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]
		self.lista[a] += self.lista[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def prime_factors(n):
	factors = dict()
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		while n % i == 0:
			if i in factors:
				factors[i] += 1
			else:
				factors[i] = 1
			n = n // i
	if n > 2:
		factors[n] = 1
	return factors

def all_factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def fibonacci_modP(n, MOD):
	if n < 2:
		return 1
	return (cached_fn(fibonacci_modP, (n + 1) // 2, MOD) * cached_fn(fibonacci_modP, n // 2, MOD) + cached_fn(fibonacci_modP, (n - 1) // 2, MOD) * cached_fn(fibonacci_modP, (n - 2) // 2, MOD)) % MOD

def factorial_modP_Wilson(n, p):
	if p <= n:
		return 0
	res = p - 1
	for i in range(n + 1, p):
		res = res * cached_fn(InverseEuler, i, p) % p
	return res

def binary(n, digits=20):
	b = bin(n)[2:]
	b = '0' * (digits - len(b)) + b
	return b

def is_prime(n):
	if n < 4:
		return True
	if n % 2 == 0:
		return False
	if n % 3 == 0:
		return False
	i = 5
	w = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += w
		w = 6 - w
	return True

def generate_primes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	return prime
factorial_modP = []

def warm_up_fac(MOD):
	global factorial_modP, fac_warm_up
	if fac_warm_up:
		return
	factorial_modP = [1 for _ in range(fac_warm_up_size + 1)]
	for i in range(2, fac_warm_up_size):
		factorial_modP[i] = factorial_modP[i - 1] * i % MOD
	fac_warm_up = True

def InverseEuler(n, MOD):
	return pow(n, MOD - 2, MOD)

def nCr(n, r, MOD):
	global fac_warm_up, factorial_modP
	if not fac_warm_up:
		warm_up_fac(MOD)
		fac_warm_up = True
	return factorial_modP[n] * (pow(factorial_modP[r], MOD - 2, MOD) * pow(factorial_modP[n - r], MOD - 2, MOD) % MOD) % MOD

def test_print(*args):
	if testingMode:
		print(args)

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def display_2D_list(li):
	for i in li:
		print(i)

def prefix_sum(li):
	sm = 0
	res = []
	for i in li:
		sm += i
		res.append(sm)
	return res

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result

def ncr(n, r):
	return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))

def binary_search(i, li):
	fn = lambda x: li[x] - x // i
	x = -1
	b = len(li)
	while b >= 1:
		while b + x < len(li) and fn(b + x) > 0:
			x += b
		b = b // 2
	return x
TestCases = True
fac_warm_up_size = 10 ** 5 + 100
optimise_for_recursion = False

def main():
	for _ in range(get_int()):
		(n, k) = get_tuple()
		if n % 2 == 0:
			print(n + k * 2)
			continue
		for i in range(2, n + 1):
			if n % i == 0:
				break
		print(n + i + (k - 1) * 2)
main()


import sys
from math import log, sqrt, factorial

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())
t = ii()
while t:
	t -= 1
	(n, k) = mi()
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		x = n
		f = 0
		for i in range(2, int(sqrt(n)) + 1):
			if n % i == 0:
				x += i
				k -= 1
				f = 1
				break
		if f == 0:
			x += n
			k -= 1
		x += 2 * k
		print(x)


import math
import sys
input = sys.stdin.readline
t = int(input())

def f(x):
	for i in range(2, math.ceil(math.sqrt(x)) + 1):
		if x % i == 0:
			return i
	return x
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	ans = n
	for i in range(k):
		if ans % 2 == 0:
			ans += (k - i) * 2
			break
		ans += f(n)
		n = ans
	print(ans)


a = [0] * (10 ** 6 + 1)
for i in range(2, 10 ** 6 + 1):
	if a[i] == 0:
		for j in range(i, 10 ** 6 + 1, i):
			if a[j] == 0:
				a[j] = i
a[1] = 1
a[0] = 1
t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	q = 0
	while k > 0:
		if n % 2 == 0:
			print(n + 2 * k)
			q = 1
			break
		n += a[n]
		k -= 1
	if q == 0:
		print(n)
	t -= 1


from collections import defaultdict, OrderedDict, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import Queue, PriorityQueue
from heapq import *
from statistics import *
from math import sqrt, log10, log2, log, gcd, ceil, floor
import fractions
import copy
from copy import deepcopy
import sys
import io
sys.setrecursionlimit(10000)
import math
import os
import bisect
import collections
mod = int(pow(10, 9)) + 7
import random
from random import *
import time
from time import time
import timeit
from timeit import timeit
import itertools
from itertools import combinations, permutations, combinations_with_replacement, product

def ncr(n, r, p=mod):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def normalncr(n, r):
	r = min(r, n - r)
	count = 1
	for i in range(n - r, n + 1):
		count *= i
	for i in range(1, r + 1):
		count //= i
	return count
inf = float('inf')
adj = defaultdict(set)
visited = defaultdict(int)

def addedge(a, b):
	adj[a].add(b)
	adj[b].add(a)

def bfs(v):
	q = Queue()
	q.put(v)
	visited[v] = 1
	while q.qsize() > 0:
		s = q.get_nowait()
		print(s)
		for i in adj[s]:
			if visited[i] == 0:
				q.put(i)
				visited[i] = 1

def dfs(v, visited):
	if visited[v] == 1:
		return
	visited[v] = 1
	print(v)
	for i in adj[v]:
		dfs(i, visited)

def reverse_bisect_right(a, x, lo=0, hi=None):
	if lo < 0:
		raise ValueError('lo must be non-negative')
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x > a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo

def reverse_bisect_left(a, x, lo=0, hi=None):
	if lo < 0:
		raise ValueError('lo must be non-negative')
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x >= a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo

def get_list():
	return list(map(int, input().split()))

def make_list(m):
	m += list(map(int, input().split()))

def get_str_list_in_int():
	return [int(i) for i in list(input())]

def get_str_list():
	return list(input())

def get_map():
	return map(int, input().split())

def input_int():
	return int(input())

def matrix(a, b):
	return [[0 for i in range(b)] for j in range(a)]

def swap(a, b):
	return (b, a)

def find_gcd(l):
	a = l[0]
	for i in range(len(l)):
		a = gcd(a, l[i])
	return a

def is_prime(n):
	sqrta = int(sqrt(n))
	for i in range(2, sqrta + 1):
		if n % i == 0:
			return 0
	return 1

def prime_factors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n //= 2
	sqrta = int(sqrt(n))
	for i in range(3, sqrta + 1, 2):
		while n % i == 0:
			n //= i
			l.append(i)
	if n > 2:
		l.append(n)
	return l

def p(a):
	if type(a) == str:
		print(a + '\n')
	else:
		print(str(a) + '\n')

def ps(a):
	if type(a) == str:
		print(a)
	else:
		print(str(a))

def kth_no_not_div_by_n(n, k):
	return k + (k - 1) // (n - 1)

def forward_array(l):
	n = len(l)
	stack = []
	forward = [0] * n
	for i in range(len(l) - 1, -1, -1):
		while len(stack) and l[stack[-1]] < l[i]:
			stack.pop()
		if len(stack) == 0:
			forward[i] = len(l)
		else:
			forward[i] = stack[-1]
		stack.append(i)
	return forward

def backward_array(l):
	n = len(l)
	stack = []
	backward = [0] * n
	for i in range(len(l)):
		while len(stack) and l[stack[-1]] < l[i]:
			stack.pop()
		if len(stack) == 0:
			backward[i] = -1
		else:
			backward[i] = stack[-1]
		stack.append(i)
	return backward

def char(a):
	return chr(a + 97)

def get_length(a):
	return 1 + int(log10(a))

def issq(n):
	sqrta = int(n ** 0.5)
	return sqrta ** 2 == n

def ceil(a, b):
	return int((a + b - 1) / b)

def equal_sum_partition(arr, n):
	sum = 0
	for i in range(n):
		sum += arr[i]
	if sum % 2 != 0:
		return False
	part = [[True for i in range(n + 1)] for j in range(sum // 2 + 1)]
	for i in range(0, n + 1):
		part[0][i] = True
	for i in range(1, sum // 2 + 1):
		part[i][0] = False
	for i in range(1, sum // 2 + 1):
		for j in range(1, n + 1):
			part[i][j] = part[i][j - 1]
			if i >= arr[j - 1]:
				part[i][j] = part[i][j] or part[i - arr[j - 1]][j - 1]
	return part[sum // 2][n]

def bin_sum_array(arr, n):
	for i in range(n):
		if arr[i] % 2 == 1:
			return i + 1
	binarray = [list(reversed(bin(i)[2:])) for i in arr]
	new_array = [0 for i in range(32)]
	for i in binarray:
		for j in range(len(i)):
			if i[j] == '1':
				new_array[j] += 1
	return new_array

def ispalindrome(s):
	return s == s[::-1]
nc = 'NO'
yc = 'YES'
ns = 'No'
ys = 'Yes'

def yesno(a):
	print(yc if a else nc)

def reduce(dict, a):
	dict[a] -= 1
	if dict[a] == 0:
		dict.pop(a)

def get_smallest(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return i
	return n
t = int(input())
for i in range(t):
	(n, k) = get_list()
	smallest = get_smallest(n)
	ans = n + smallest + (k - 1) * 2
	print(ans)


t = int(input())

def findfac(n):
	div = 1
	for i in range(2, n + 1):
		if n % i == 0:
			div = i
			break
	return div
for xx in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 1:
		sf = findfac(n)
		n += sf
		k -= 1
	n += 2 * k
	print(n)


def factors(n, k):
	while k:
		if n % 2 == 0:
			val = n + k * 2
			return val
		n += find_smallest(n)
		k -= 1
	return n

def find_smallest(n):
	for i in range(3, n + 1):
		if n % i == 0:
			return i
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().rstrip().split()))
	print(factors(n, k))


Q = int(input())
for _ in range(Q):
	(n, k) = map(int, input().split())
	if n % 2 == 1:
		d = 2
		div = -1
		while d * d <= n:
			if n % d == 0:
				div = d
				break
			d += 1
		if div == -1:
			div = n
		n += div
		k -= 1
	ret = n + 2 * k
	print(ret)


import math
n = int(input())

def funci(a):
	val = 0
	for i in range(2, a + 1):
		if a % i == 0:
			val = i
			break
	return val
for i in range(n):
	(a, b) = map(int, input().split())
	if a % 2 == 0:
		z = funci(a)
		print(a + 2 * b)
	else:
		z = funci(a)
		print(a + (b - 1) * 2 + z)


for _ in range(int(input())):
	(n, k) = [int(s) for s in input().split()]
	ind = n
	for i in range(2, n + 1):
		if n % i == 0:
			ind = i
			break
	print(n + ind + (k - 1) * 2)


q = int(input())
while q != 0:
	q -= 1
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		a = 0
		for i in range(2, n + 1):
			if n % i == 0:
				a = i
				break
		print(n + a + 2 * (k - 1))


from sys import stdin, stdout
for testcases in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	res = -1
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			res = i
			break
	if res == -1:
		res = n
	k -= 1
	n += res
	n += 2 * k
	stdout.write(str(n) + '\n')


t = int(input())

def f(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i

def solve():
	(n, k) = map(int, input().split())
	count = 0
	for i in range(k):
		if n % 2 == 0:
			break
		else:
			n = n + f(n)
			count += 1
	n += (k - count) * 2
	print(n)
for i in range(t):
	solve()


N = int(input())
for _ in range(N):
	(x, y) = map(int, input().split())
	l = []
	ans = 0
	while y > 0:
		mi = x
		if x % 2 == 0:
			ans = 0
			ans = ans + x + 2 * y
			break
		else:
			for i in range(2, x):
				if x % i == 0:
					mi = min(i, mi)
				if mi != x:
					break
			ans = ans + x + mi
		x = x + mi
		y = y - 1
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		ans = n + 2 * k
	else:
		dd = n
		for d in range(3, 1 + int(n ** 0.5)):
			if n % d == 0:
				dd = d
				break
		ans = n + dd + 2 * (k - 1)
	print(ans)


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	d = 2
	while n % d:
		d += 1
	answer = n + d + 2 * (k - 1)
	print(answer)


def solve1():
	(n, k) = map(int, input().split())
	cnt = 0

	def factor(num):
		for i in range(3, int(num ** 0.5) + 1, 2):
			if num % i == 0:
				return i
		return num
	while n & 1:
		n += factor(n)
		cnt += 1
	print((k - cnt) * 2 + n)
for _ in range(int(input())):
	solve1()


import math
top_prime = 10 ** 5

def get_primes():
	primes = []
	bits = [True] * (top_prime + 1)
	bits[0] = bits[1] = False
	cap = int(math.sqrt(top_prime))
	for i in range(2, cap + 1):
		if bits[i]:
			primes.append(i)
			for j in range(i * i, top_prime + 1, i):
				bits[j] = False
	for i in range(cap, top_prime + 1):
		if bits[i]:
			primes.append(i)
	return set(primes)
primes = get_primes()
ordered_primes = list(sorted(primes))

def first_div(n):
	if n in primes:
		return n
	cap = int(math.sqrt(n))
	for prime in ordered_primes:
		if prime > cap + 2:
			return n
		if n % prime == 0:
			return prime
	return n
n_cases = int(input())
for case_num in range(1, n_cases + 1):
	(n, k) = [int(x) for x in input().split()]
	while k:
		if n % 2 == 0:
			n += 2 * k
			k = 0
		else:
			n += first_div(n)
			k -= 1
	print(n)


import math
t = int(input())
for i in range(t):
	sa = input().split(' ')
	n = int(sa[0])
	k = int(sa[1])
	rootn = int(math.sqrt(n))
	div = 1
	for i in range(2, rootn + 1):
		if n % i == 0:
			div = i
			break
	if div == 1:
		div = n
	while k > 0:
		if div == 2:
			break
		n += div
		k -= 1
		for i in range(2, div):
			if n % i == 0:
				div = i
				break
	if k > 0:
		if div == 2:
			n += div * k
	print(n)


import math

def isOdd(n):
	for i in range(2, n // 2):
		if n % i == 0:
			return i
	return n

def calcN(n, k):
	fn = 0
	if n % 2 != 0:
		fn = isOdd(n)
		if fn != n:
			n = n + fn
		else:
			n += n
		n = n + 2 * (k - 1)
	elif n % 2 == 0:
		n = n + 2 * k
	print(n)

def main():
	t = int(input())
	for i in range(t):
		(n, k) = tuple(map(int, input().split()))
		calcN(n, k)
main()


for _ in range(int(input())):
	(m, k) = map(int, input().split())
	jg = 0
	am = m
	for i in range(2, m):
		if m % i == 0:
			am = min(i, m / i)
			break
	print(m + am + 2 * (k - 1))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n
	i = int(n / 2)
	while i >= 2:
		if n % i == 0:
			ans = min(ans, i)
		i = i - 1
	n = n + ans
	if k > 1:
		n = n + 2 * (k - 1)
	print(n)


def f(a, b):
	tmp = 0
	if a % 2 == 0:
		return a + b * 2
	else:
		for i in range(2, int(a ** 0.5) + 1):
			if a % i == 0:
				tmp = i
				break
		if tmp == 0:
			tmp = a
		return a + tmp + (b - 1) * 2
t = int(input())
cnt = 0
while cnt < t:
	cnt += 1
	(n, k) = [int(i) for i in input().split()]
	res = f(n, k)
	print(res)


def factors(n):
	(l1, l2) = ([], [])
	for i in range(1, int(n ** 0.5) + 1):
		(q, r) = (n // i, n % i)
		if r == 0:
			l1.append(i)
			l2.append(q)
	if l1[-1] == l2[-1]:
		l1.pop()
	l2.reverse()
	return l1 + l2
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 != 0:
		n += factors(n)[1]
	else:
		n += 2
	if k - 1 > 0:
		n += 2 * (k - 1)
	print(n)


t = int(input())
ans = []

def sieve(n):
	prime = [True] * (n + 1)
	p = 2
	while p * p <= n:
		if prime[p]:
			for j in range(p * p, n + 1, p):
				prime[j] = False
		p += 1
	for u in range(2, n + 1):
		if prime[u]:
			ans.append(u)
for i in range(t):
	(inp, k) = map(int, input().split())
	sieve(inp)
	if inp % 2 == 0:
		print(inp + 2 * k)
	else:
		for j in ans:
			if inp % j == 0:
				print(inp + j + 2 * (k - 1))
				break


import math as mt
MAXN = 1000001
spf = [0 for i in range(MAXN)]

def sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, mt.ceil(mt.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def getFactorization(x):
	ret = list()
	while x != 1:
		ret.append(spf[x])
		x = x // spf[x]
	return ret
sieve()

def processInputs():
	(N, K) = map(int, input().strip().split())
	if N % 2 == 0:
		return N + K * 2
	d = min(getFactorization(N))
	N = N + d
	return N + (K - 1) * 2
t = int(input())
for _ in range(t):
	print(processInputs())


import sys
input = sys.stdin.buffer.readline

def isPrime(n):
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def main():
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		return n + 2 * k
	elif isPrime(n):
		return 2 * n + 2 * (k - 1)
	else:
		i = 2
		while i and k:
			if n % i == 0:
				n += i
				k -= 1
			if n % 2 == 0:
				return n + 2 * k
				break
			i += 1
		return n
t = int(input())
while t:
	t -= 1
	print(main())


from math import sqrt

def d(n, r):
	if n & 1 == 0:
		return 2
	elif n % 3 == 0:
		return 3
	for x in range(5, r, 6):
		if n % x == 0:
			return x
		xt = x + 2
		if n % xt == 0:
			return xt
	return n

def f(n):
	r = int(sqrt(n)) + 1
	b = d(n, r)
	return n + b
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	ret = f(n)
	ret += k - 1 << 1
	print(ret)


import math
t = int(input())

def f_n(num):
	j = 2
	div = 0
	while j <= math.sqrt(num):
		if n % j == 0:
			div = j
			break
		j += 1
	if div == 0:
		div = num
	return div
for i in range(t):
	(n, k) = map(int, input().split())
	f = 0
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + 2 * (k - 1) + f_n(n))


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	prime = True
	for i in range(2, int(N ** 0.5 + 1)):
		if N % i == 0:
			divisor = i
			prime = False
			break
	if prime == True:
		print(N + N + (K - 1) * 2)
	else:
		print(2 * (K - 1) + N + divisor)


n = int(input())

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
		if len(divisors) >= 3:
			break
	divisors.sort()
	return divisors[1]
for i in range(n):
	c = 0
	(a, b) = map(int, input().split())
	for j in range(b):
		a += make_divisors(a)
		if make_divisors(a) == 2:
			c = j
			break
	a += (b - c - 1) * 2
	print(a)


out = []
try:
	for _ in range(int(input())):
		(a, b) = [int(d) for d in input().split()]
		c = 2
		for i in range(b):
			while a % c != 0:
				c = c + 1
			a = a + c
			c = 2
			if i > 0 and a % 2 == 0:
				a = a + (b - i - 1) * 2
				break
		out.append(a)
except:
	pass
for i in range(len(out)):
	print(out[i])


t = int(input())
N_max = int(1000000.0)
prime = [1] * (N_max + 1)
sieve = []
p = 2
while p * p <= N_max:
	if prime[p] == 1:
		sieve.append(p)
		for j in range(p * p, N_max + 1, p):
			prime[p] = 0
	p = p + 1

def f(n):
	i = 2
	while i <= n:
		if n % i == 0:
			return i
		i = i + 1
	return n
while t:
	t = t - 1
	(N, K) = input().split(' ')
	(n, k) = (int(N), int(K))
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + f(n) + 2 * (k - 1))


def isprime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	while k > 0:
		if n % 2 == 0:
			n += k * 2
			break
		if isprime(n):
			n += n
		else:
			for i in range(3, n // 2):
				if n % i == 0:
					n += i
					break
		k -= 1
	print(n)
	t -= 1


def sd(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ind = 0
	currn = 0
	if n % 2 == 0:
		ans = k * 2 + n
		print(ans)
	else:
		flag = 0
		currn = 0
		for i in range(1, k + 1):
			a = sd(n)
			if a % 2 == 0:
				ind = k - i
				flag = 1
				currn = a
				break
			n = a + n
		if flag == 1:
			ans = n + (ind + 1) * 2
			print(ans)
		else:
			print(n)


def f(x):
	for a in range(2, x // 2):
		if x % a == 0:
			return a
	else:
		return x
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	num = 0
	if x % 2 == 0:
		x += 2 * y
	else:
		x += f(x)
		x += 2 * (y - 1)
	print(x)


import sys
input = sys.stdin.readline

def mult_input():
	return map(int, input().split())

def list_input():
	return list(map(int, input().split()))
for nt in range(int(input())):
	(n, k) = map(int, input().split())
	for i in range(2, n + 1):
		if n % i == 0:
			num = i
			break
	print(n + i + 2 * (k - 1))


def small(a):
	for i in range(2, a // 2 + 1):
		if a % i == 0:
			return i
	return a
t = int(input())
for _ in range(0, t):
	(a, b) = list(map(int, input().split()))
	ans = a + small(a)
	ans = ans + 2 * (b - 1)
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	f = True
	for j in range(2, int(n ** 0.5) + 3):
		if n % j == 0:
			print(n + j + 2 * (k - 1))
			f = False
			break
	if f:
		print(n + n + 2 * (k - 1))


def doLoops(n, k):
	if n & 1 ^ 1:
		return n + 2 * k
	else:
		p = 0
		for i in range(n, 1, -1):
			if n % i == 0:
				p = i
		return n + p + 2 * (k - 1)
a = int(input())
d = []
for i in range(a):
	i = input().split()
	d.append(doLoops(int(i[0]), int(i[1])))
[print(i) for i in d]


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		for j in range(2, 10 ** 6 + 1):
			if n % j == 0:
				n += j
				break
		print(n + 2 * (k - 1))


ii = lambda : int(input())
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
for _ in range(ii()):
	(n, k) = f()
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		while n % 2 != 0 and k >= 1:
			l = 0
			for i in range(3, n + 1):
				if n % i == 0:
					l = i
					break
			if k >= 1:
				n = n + l
				k = k - 1
		if n % 2 == 0:
			print(n + 2 * k)
		else:
			print(n)


def mindiv(n):
	for div in range(2, n + 1):
		if n % div == 0:
			return div
for i in range(int(input())):
	(n, k) = map(int, input().split())
	while n % 2 == 1 and k > 0:
		n += mindiv(n)
		k -= 1
	n += 2 * k
	print(n)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, functools

def solve(line):
	(n, k) = map(int, line.split())
	f = None
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			f = i
			break
	return n + i + (k - 1) * 2 if f != None else 2 * n + (k - 1) * 2
T = int(sys.stdin.readline())
t = 0
while True:
	line = sys.stdin.readline().rstrip()
	if not line:
		break
	print(solve(line))
	t += 1


import math
tc = int(input())
for _ in range(tc):
	(n, k) = list(map(int, input().split()))
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		place = -69
		for i in range(3, int(math.sqrt(n) + 1)):
			if n % i == 0:
				place = i
				break
		if place == -69:
			print(2 * n + 2 * (k - 1))
		else:
			print(n + 2 * (k - 1) + place)


def f(a):
	for i in range(2, a // 2 + 2):
		if a % i == 0:
			return i
	return a

def solution():
	(n, k) = list(map(lambda x: int(x), input().split()))
	r = f(n)
	if r != 2:
		print(n + r + 2 * (k - 1))
	else:
		print(n + r * k)
t = int(input())
for _ in range(t):
	solution()


import math
for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	paichi = False
	for j in range(k):
		if n % 2 == 0:
			n += 2 * (k - j)
			break
		else:
			for a in range(3, math.floor(math.sqrt(n)) + 1, 2):
				if n % a == 0:
					n += a
					paichi = True
					break
				else:
					paichi = False
			if paichi == False:
				n += n
	print(n)


t = int(input())
for j in range(t):
	(n, k) = input().split(' ')
	n = int(n)
	k = int(k)
	i = 2
	while n % i != 0:
		i += 1
	print(n + i + (k - 1) * 2)


import math

def getFirst(n):
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return i
	else:
		return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		n += 2 * k
	else:
		x = getFirst(n)
		n += x
		n += 2 * (k - 1)
	print(n)


import math
import sys
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	for i in range(k):
		if n % 2 == 0:
			n += 2 * (k - i)
			break
		else:
			for d in range(3, 1000, 2):
				if n % d == 0 or d * d > n:
					break
			if n % d > 0:
				d = n
			n += d
	print(n)


t = int(input())
for q in range(t):
	ch = input()
	L = [int(i) for i in ch.split()]
	(n, k) = (L[0], L[1])
	q = n
	p = int(n ** 0.5)
	for i in range(2, p + 2):
		if n % i == 0:
			q = i
			break
	n = n + q
	n = n + 2 * (k - 1)
	print(n)


import math

def primeFactors(n):
	l = []
	c = 2
	while n > 1:
		if n % c == 0:
			l.append(c)
			n = n / c
		else:
			c = c + 1
	return l

def primeFactors(n):
	l = []
	c = 2
	while n > 1:
		if n % c == 0:
			l.append(c)
			n = n / c
		else:
			c = c + 1
	return l

def prime(n):
	prime_flag = 0
	if n > 1:
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0:
				prime_flag = 1
				break
	return prime_flag

def min_factor(n):
	mini = 100000000
	i = 2
	while i * i <= n:
		if n % i == 0:
			mini = min(mini, i)
		i += 1
	mini = min(mini, n)
	return mini
t = int(input())
while t:
	l = list(map(int, input().split()))
	n = l[0]
	k = l[1]
	a = min_factor(n)
	ans = n + a
	ans = ans + (k - 1) * 2
	print(ans)
	t = t - 1


from math import *

def main():
	t = int(input())
	for tc in range(0, t):
		(n, k) = map(int, input().split(' '))
		div = -1
		for i in range(2, ceil(sqrt(n)) + 1):
			if n % i == 0:
				div = i
				break
		if div == -1:
			div = n
		n += div
		k -= 1
		n += k * 2
		print(n)
main()


t = int(input())
for i in range(t):
	(n, k) = [int(i) for i in input().split()]
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		div = 0
		for j in range(int(n ** 0.5) + 1):
			if n % (j + 2) == 0:
				div = j + 2
				break
		if div == 0:
			print(2 * n + 2 * (k - 1))
		else:
			print(n + div + 2 * (k - 1))


t = int(input(''))
for y in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if n % 2 == 0:
		n = n + 2 * k
	else:
		for x in range(3, n + 1, 2):
			if n % x == 0:
				n += x
				n = n + 2 * (k - 1)
				break
	print(n)


def ab(n):
	global d
	if n in d:
		return d[n]
	i = 2
	while i <= n / i:
		if n % i == 0:
			d[n] = i
			return i
		if i == 2:
			i = 1
		i += 2
	d[n] = n
	return n
t = int(input())
d = {}
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	if n == 1:
		print(k * 2)
		continue
	elif n % 2 == 0:
		print(n + k * 2)
		continue
	while k > 0:
		n = ab(n) + n
		k -= 1
		if n % 2 == 0:
			n = n + k * 2
			break
	print(n)


t = int(input())
for a in range(t):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	if n % 2 == 0:
		print(n + 2 * k)
	if n % 2 != 0:
		for j in range(2, n + 1):
			if j % 2 != 0 and n % j == 0:
				print(n + j + (k - 1) * 2)
				break
			else:
				continue


from sys import stdin

def main():
	readline = stdin.readline
	t = int(readline())
	ans = []
	for _ in range(t):
		(n, k) = map(int, readline().split())
		if n % 2 == 0:
			n += 2 * k
			ans.append(n)
		else:
			for m in range(3, n + 1, 2):
				if m * m > n:
					m = n
					break
				if n % m == 0:
					break
			n += m
			k -= 1
			n += 2 * k
			ans.append(n)
	for i in range(t):
		print(ans[i])
main()


for i in range(int(input())):
	(n, m) = map(int, input().split())
	j = 2
	while n % j != 0 and j <= int(n ** 0.5) + 1:
		j += 1
	if j > int(n ** 0.5) + 1:
		j = n
	print(n + j + 2 * (m - 1))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		ls = []
		for j in range(1, n + 1):
			if n % j == 0:
				ls.append(j)
			if len(ls) == 2:
				break
		print(n + ls[1] + 2 * (k - 1))


prime = [2, 3, 5, 7, 11, 13, 17, 19]

def GeneratePrime(start=21):
	for x in range(start, 1000, 2):
		isprime = True
		for v in prime:
			if x % v == 0:
				isprime = False
				break
		if isprime:
			prime.append(x)
GeneratePrime()
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	bFound = False
	if n % 2 == 0:
		n += k * 2
	else:
		for x in prime:
			if n % x == 0:
				bFound = True
				n += x
				break
		if not bFound:
			n += n
		n += (k - 1) * 2
	print(n)


def sD(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = int(input())
for i in range(t):
	b = list(map(int, input().split()))
	(n, k) = (b[0], b[1])
	p = sD(n)
	print(n + p + 2 * (k - 1))


tc = int(input())
while tc:
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		f = 0
		for i in range(3, n + 1, 2):
			if n % i == 0:
				f = i
				break
		n += f
		k -= 1
		print(n + 2 * k)
	tc -= 1


import math

def fun(n):
	i = 3
	while i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		d = fun(n)
		ans = n + d + (k - 1) * 2
		print(ans)


n1 = int(input())
for i in range(n1):
	(m, n) = map(int, input().split())
	if m % 2 == 0:
		print(m + n * 2)
	else:
		for j in range(2, m + 1):
			if m % j == 0:
				print(m + j + (n - 1) * 2)
				break


def getn(nn):
	vv = nn
	for ii in range(2, nn + 1):
		if nn % ii == 0:
			vv = ii
			break
	return vv
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	v = getn(n)
	if v == n:
		k -= 1
		n = v + n
		v = 2
	else:
		k -= 1
		n = v + n
		v = 2
	print(n + v * k)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		i = 3
		am = True
		while i * i <= n:
			if n % i == 0:
				am = False
				break
			i += 1
		if am:
			i = n
		print(n + i + 2 * (k - 1))


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def solve():
	(n, k) = rl()
	for i in range(2, int(n ** 0.5) + 2):
		if n % i == 0:
			d = i
			break
	else:
		d = n
	print(n + d + 2 * (k - 1))
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


def main(n, k):
	if n & 1 == 0:
		return n + 2 * k
	for i in range(3, n + 1):
		if n % i == 0:
			return n + i + 2 * (k - 1)
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(main(n, k))


import math

def divisors(n):
	divs = [1]
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			divs.extend([i, n / i])
	divs.extend([n])
	m = list(set(divs))
	m.remove(1)
	return min(m)
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	m = divisors(n)
	n += m + 2 * (k - 1)
	print(n)


for i in [0] * int(input()):
	(a, b) = list(map(int, input().split()))
	if a & 1 ^ 1:
		print(a + 2 * b)
	else:
		i = 3
		f = 1
		ans = a
		while i * i <= a:
			if a % i == 0:
				ans += i
				f = 0
				break
			i += 1
		if f:
			ans += a
		print(ans + 2 * (b - 1))


import math

def least(a):
	if a & 1 == 0:
		return 2
	else:
		for i in range(3, int(math.sqrt(a)) + 1, 2):
			if a % i == 0:
				return i
		return a
t = int(input())
for _ in range(t):
	(a, k) = map(int, input().split())
	a += least(a) + 2 * (k - 1)
	print(a)


def int_input():
	return int(input())

def ints_input():
	return (int(x) for x in input().split())
t = int_input()
for _ in range(t):
	(n, k) = ints_input()
	if n & 1 == 0:
		print(n + k + k)
	else:
		for i in range(3, n + 1, 2):
			if n % i == 0:
				print(n + i + 2 * (k - 1))
				break


for i in range(0, int(input())):
	(a, b) = [int(x) for x in input().split()]
	temp = a
	flag = 0
	if a % 2 == 0:
		temp = temp + 2 * b
		print(temp)
	else:
		for i in range(2, a + 1):
			if temp % i == 0:
				temp = temp + i
				temp = temp + 2 * (b - 1)
				print(temp)
				break


def pfac(num):
	if num < 4 or num == 5:
		return num
	if not num & 1:
		return 2
	if not num % 3:
		return 3
	if not num % 5:
		return 5
	d = 6
	while d * d <= num:
		if not num % (d + 1):
			return d + 1
		if not num % (d - 1):
			return d - 1
		d += 6
	return num
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if not n & 1:
		print(n + 2 * k)
		continue
	else:
		n += pfac(n)
		print(n + 2 * (k - 1))
		continue


n = int(input())
while n:
	a = [int(x) for x in input().split()]
	targ = a[0]
	times = a[1]
	thingy = 0
	i = 2
	while i <= int(targ ** (1 / 2)):
		if targ % i == 0:
			thingy = i
			break
		i += 1
	if i == 1 + int(targ ** (1 / 2)):
		thingy = targ
	print(thingy + targ + (times - 1) * 2)
	n -= 1


from sys import stdin
input = stdin.readline
import math
import bisect
for xoxo in range(1):
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		i = 2
		while True:
			if n % i == 0:
				break
			i += 1
		k -= 1
		print(k * 2 + i + n)


t = int(input())

def f(n):
	i = 2
	while i <= n ** (1 / 2):
		if n % i == 0:
			if n / i == i:
				return i
			else:
				return min(int(i), int(n / i))
		i = i + 1
	else:
		return n
for i in range(t):
	(n, k) = [int(i) for i in input().split()]
	if n % 2 == 0:
		q = k * 2
		print(n + q)
	else:
		print(n + f(n) + (k - 1) * 2)


tc = int(input())
for _ in range(tc):
	(n, a) = input().split()
	a = int(a)
	n = int(n)
	for i in range(2, n + 1):
		if n % i == 0:
			print(n + i + 2 * (a - 1))
			break


import collections
import itertools
import sys
from collections import defaultdict, Counter
from math import sqrt
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def ds(d):
	for i in range(2, d + 1):
		if d % i == 0:
			return i

def main():
	d = inp()
	for i in range(d):
		(a, b) = inlt()
		v = ds(a)
		while v != 2:
			a += v
			b -= 1
			v = ds(a)
		a += 2 * b
		print(a)
main()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	(n, k) = sep()
	if n % 2 == 0:
		n += 2 * k
	else:
		div = n
		for i in range(2, floor(n ** 0.5) + 1):
			if n % i == 0:
				div = i
				break
		n += div
		n += 2 * (k - 1)
	print(n)
testcase(int(inp()))


import math

def check(n):
	ans = [n]
	for q in range(2, int(math.sqrt(n)) + 1):
		if n % q == 0:
			return q
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	while k:
		temp = check(n)
		n = n + temp
		k -= 1
		if n % 2 == 0:
			break
	if k == 0:
		print(n)
	else:
		print(n + 2 * k)


def smallfact(n):
	x = 2
	p = n // 2
	for l in range(p):
		if n % x == 0:
			return x
		x += 1
	return n
t = int(input())
for z in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		n += 2 * k
	else:
		n += 2 * (k - 1) + smallfact(n)
	print(n)


import math

def divisores(n):
	lista = []
	for k in range(1, int(math.sqrt(n) + 1)):
		if n % k == 0:
			yield k
			if k * k != n:
				lista.append(n // k)
	for d in reversed(lista):
		yield d
t = int(input())
for q in range(t):
	(n, k) = list(map(int, input().split(' ')))
	l = list(divisores(n))
	if l[1] != 2:
		n += l[1]
		n += 2 * (k - 1)
	else:
		n += 2 * k
	print(n)


a = input()
i = int(a)
x = 0
y = 2
fac_n = []
while x < i:
	x += 1
	b = input()
	s = b.split(' ')
	n = int(s[0])
	k = int(s[1])
	while y <= n:
		if n % y == 0:
			fac_n.append(y)
		y += 1
	z = int(fac_n[0])
	if n % 2 == 0:
		print(n + 2 * k)
	if n % 2 != 0:
		print(int(n + 2 * (k - 1) + z))
	y = 2
	fac_n = []


import math

def Divisor(a):
	i = 1
	lis = []
	while i <= math.sqrt(a):
		if n % i == 0:
			if n / i == i:
				lis.append(i)
			else:
				lis.append(i)
		i += 1
	len1 = len(lis)
	if len1 == 1:
		return a
	else:
		return lis[1]
t = int(input())
for i in range(t):
	num1 = list(map(int, input().split()))
	n = num1[0]
	k = num1[1]
	b = Divisor(n)
	n += b
	n += (k - 1) * 2
	print(n)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	d = None
	if k == 0:
		print(n)
		continue
	for i in range(2, int(pow(n, 0.5) + 1)):
		if n % i == 0:
			d = i
			break
	if d:
		ans = d + n
		k -= 1
		ans += 2 * k
	else:
		ans = 2 * n
		k -= 1
		ans += k * 2
	print(ans)


import math

def di(n):
	if n % 2 == 0:
		return 2
	for i in range(3, n, 2):
		if n % i == 0:
			return i
	return n
for i in range(int(input())):
	arr = list(map(int, input().split(' ')))
	if arr[0] % 2 == 0:
		print(arr[0] + 2 * arr[1])
	else:
		print(arr[0] + 2 * (arr[1] - 1) + di(arr[0]))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	b = 2
	while n % b != 0:
		b += 1
	n += b
	print(n + (k - 1) * 2)


import math

def fact(n):
	(min, min1) = (n, n)
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i != 1:
				if i > n / i:
					min1 = n / i
				else:
					min1 = i
			else:
				min1 = n / i
		if min > min1:
			min = min1
	return int(min)
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		r = fact(n)
		print(n + r + 2 * (k - 1))


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().strip().split())

def from_file(f):
	return f.readline

def get_min_p(n):
	for i in range(2, n):
		if n % i == 0:
			return i
		if i * i > n:
			break
	return n

def solution(n, k):
	p = get_min_p(n)
	if p == 2:
		return n + 2 * k
	res = n + p + 2 * (k - 1)
	return res
t = inp()
for _ in range(t):
	(n, k) = invr()
	print(solution(n, k))


def f(a, b):
	b -= 1
	if a % 2 == 0:
		return a + 2 * (b + 1)
	for i in range(2, int(a ** (1 / 2)) + 1):
		if a % i == 0:
			a += i
			break
	else:
		a = 2 * a + b * 2
		return a
	if b == 0:
		return a
	else:
		return f(a, b)
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	print(f(n, k))


from math import sqrt
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	div = n
	for i in range(int(sqrt(n)) + 10, 1, -1):
		if n % i == 0:
			div = i
	n += div
	k -= 1
	ans = n + 2 * k
	print(ans)


from collections import *
from bisect import *
from math import *
import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		s = n
		p = 0
		for i in range(2, int(pow(n, 0.5)) + 1):
			if n % i == 0:
				p = i
				s += i
				break
		if p == 0:
			s += n
		print(s + (k - 1) * 2)


def s_divisor(n):
	i = 3
	while True:
		if n % i == 0:
			return i
		i += 2
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	if n % 2 == 0:
		print(n + m * 2)
	else:
		print(n + s_divisor(n) + (m - 1) * 2)


import math

def first(n):
	if n % 2 == 0:
		return 2
	for i in range(3, math.ceil(math.sqrt(n)) + 1, 2):
		if n % i == 0:
			return i
	return n

def solution(n, k):
	p = first(n)
	return n + p + 2 * (k - 1)
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	print(solution(n, k))


def f(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return i
	return n
t = int(input())
answers = []
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	n_new = n + f(n)
	k_new = k - 1
	ans = n_new + (k - 1) * 2
	answers.append(ans)
print(*answers, sep='\n')


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	minDivisor = n
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			minDivisor = i
			break
	n += minDivisor
	n += 2 * (k - 1)
	print(n)


temp = []
try:
	for _ in range(int(input())):
		(n, k) = [int(x) for x in input().split()]
		a = 2
		for i in range(k):
			while n % a != 0:
				a = a + 1
			n = n + a
			a = 2
			if i > 0 and n % 2 == 0:
				n = n + (k - i - 1) * 2
				break
		temp.append(n)
except:
	pass
for i in range(len(temp)):
	print(temp[i])


import math
t = int(input())
while t > 0:
	t -= 1
	(a, b) = map(int, input().split())
	x = 2
	for i in range(2, a + 1):
		if a % i == 0:
			x = i
			break
	sum = a + x + 2 * (b - 1)
	print(sum)


from math import floor, sqrt
T = int(input())

def smallest_factor(N):
	ans = 2
	while N % ans != 0:
		ans += 1
		if ans > floor(sqrt(N)):
			ans = N
	return ans
for _ in range(T):
	(N, K) = map(int, input().split())
	N += smallest_factor(N)
	N += (K - 1) * 2
	print(N)


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
import bisect as bi
import heapq

def I():
	return int(input())

def In():
	return map(int, input().split())

def main():
	try:
		(n, k) = In()
		ans = 0
		for j in range(2, n + 1):
			if n % j == 0:
				ans = j
				break
		n += ans
		n += (k - 1) * 2
		print(n)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


def func(x):
	i = 2
	while i * i <= x:
		if x % i == 0:
			return i
		i += 1
	return x
ans = []
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	ans.append(n + func(n) + 2 * (k - 1))
for i in ans:
	print(i)


t = int(input())
for w in range(t):
	(n, k) = (int(i) for i in input().split())
	for i in range(2, n + 1):
		if n % i == 0:
			k1 = i
			break
	print(n + k1 + 2 * (k - 1))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	f = 0
	if a == 3:
		print(2 * a + 2 * (b - 1))
	elif a % 2 == 0:
		print(a + b * 2)
	else:
		for i in range(2, a // 2 + 2):
			if a % i == 0:
				a += i
				break
			if i == a // 2:
				a += a
				break
		print(a + 2 * (b - 1))


from math import *

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	res = n
	x = smallestDivisor(n)
	res += x
	n = res
	k -= 1
	res += 2 * k
	print(res)


import math
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	prev = n
	if n % 2 == 0:
		prev = n
		n = n + 2 * k
		k = 0
	else:
		while k != 0:
			x = 0
			for i in range(2, int(math.sqrt(n)) + 1):
				if n % 2 == 0:
					n = n + 2 * k
					k = 0
					x = 1
					break
				elif n % i == 0:
					prev = n
					n = n + i
					k = k - 1
			if x == 1:
				break
			if n == prev:
				prev = n
				n = 2 * n
				k = k - 1
	print(n)


from math import sqrt
from collections import defaultdict as dd
import sys
input = sys.stdin.readline
import bisect
t = int(input())
while t:
	(n, k) = map(int, input().split())
	for i in range(2, n + 1):
		if n % i == 0:
			ind = i
			break
	n = n + i
	n = (k - 1) * 2 + n
	print(n)
	t -= 1


import math

def f(x):
	for i in range(2, int(math.sqrt(x)) + 2):
		if x % i == 0:
			return i
	return x
T = int(input())
while T > 0:
	T -= 1
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		print(n + f(n) + (k - 1) * 2)


def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	sum = smallestDivisor(n) + n + k * 2 - 2
	print(sum)


import math

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
t = inp()

def f(n):
	limit = int(math.sqrt(n + 1))
	for i in range(2, limit + 1):
		if n % i == 0:
			return i
	return n
while t:
	(n, k) = invr()
	d = f(n)
	n = n + d + 2 * (k - 1)
	print(n)
	t -= 1


def fa(x):
	for i in range(2, x + 1):
		if x % i == 0:
			return i
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		n1 = fa(n)
		print(n + n1 + (k - 1) * 2)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
		continue
	else:
		x = n
		h = n ** 0.5
		h = int(h)
		for i in range(2, h + 1):
			if n % i == 0:
				x = i
				break
		n = n + x
		print(n + 2 * (k - 1))
		continue


import math

def factor(n):
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return i
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(n + factor(n) + (k - 1) * 2)


t = int(input())
while t:
	(n, k) = map(int, input().split())
	s = 0
	for j in range(2, n + 1):
		if n % j == 0:
			s = j
			break
	l = 0
	f = 0
	for i in range(k):
		if n % 2 == 0:
			n += 2
			l = i
			f = 1
			break
		else:
			n += s
	if f == 1:
		n += (k - l - 1) * 2
	print(n)
	t -= 1


T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	for j in range(2):
		x = 2
		while n % x != 0:
			x += 1
		n = n + x
	y = x * (k - 2)
	print(n + y)


def md(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return i
	return n
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	n += md(n)
	print(n + (k - 1) * 2)


from math import sqrt
N = int(input())
answers = []
for i in range(N):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		answers.append(2 * k + n)
	else:
		last_n = n
		for z in range(2, int(sqrt(n) + 1)):
			if n % z == 0:
				n += z
				break
		if last_n == n:
			n += n
		answers.append(2 * (k - 1) + n)
for i in answers:
	print(i)


t = int(input())
for fk in range(t):
	(n, k) = [int(x) for x in input().split()]
	i = 2
	while n % i != 0:
		i += 1
	print(n + i + k * 2 - 2)


t = int(input())
for k in range(t):
	y = list(map(int, input().split(' ')))
	a = y[0]
	b = y[1]
	f = 0
	if a % 2 != 0:
		for i in range(2, a // 2 + 1, 1):
			if a % i == 0:
				r = i
				f = 1
				break
		if f != 1:
			r = a
		s = a + r
		s = s + 2 * (b - 1)
		print(s)
	else:
		s = a + 2 * b
		print(s)


try:
	w = int(input())
	for _ in range(w):
		(n, k) = map(int, input().split())
		if n % 2 != 0:
			i = 3
			while i <= n:
				if n % i == 0:
					ans = i + n + 2 * (k - 1)
					print(ans)
					break
				i += 2
		else:
			ans = 2 * k + n
			print(ans)
except:
	pass


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	j = 2
	while n % j:
		j += 1
	print(n + j + 2 * k - 2)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		flag = True
		count = 1
		while flag:
			count += 2
			if n % count == 0:
				flag = False
		print(n + count + 2 * (k - 1))


def a(x):
	for i in range(2, x + 1):
		if x % i == 0:
			return i
answer = []
for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	f = a(n)
	y = f + n + 2 * (k - 1)
	answer.append(y)
for i in range(len(answer)):
	if answer[i] == -1:
		print(-1)
	else:
		print(answer[i])


import sys
input = sys.stdin.buffer.readline
from math import sqrt, ceil

def I():
	return list(map(int, input().split()))

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a
for __ in range(int(input())):
	(n, k) = I()
	if n % 2 == 0:
		print(n + 2 * k)
		continue
	f = 0
	least = n
	for i in range(2, n):
		if n % i == 0:
			f = 1
			least = i
			break
	print(n + least + 2 * (k - 1))


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(moves, n):
	val = (moves + 1) // 2
	rem = moves - val
	sol = (val + 1) * (rem + 1)
	return sol < n

def sortSecond(val):
	return val[1]
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect
import functools as fnt

def f(n):
	x = n
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			x = i
			break
	return x

def solve():
	(n, k) = read()
	val = f(n)
	n += val
	k -= 1
	while val != 2:
		val = f(n)
		n += val
		k -= 1
	n += 2 * k
	print(n)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = scanner()
for i in range(t):
	solve()


def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	elif isPrime(n):
		g = n + n
		print(g + 2 * (k - 1))
	elif n % 2 != 0:
		k1 = 0
		for i in range(2, n // 2):
			if n % i == 0:
				k1 = i
				break
		g = n + k1
		print(g + 2 * (k - 1))


def smallest_divisor(num):
	divisor = 2
	while True:
		if n % divisor == 0:
			break
		else:
			divisor = divisor + 1
	return divisor
tests = int(input())
while tests > 0:
	(n, k) = [int(i) for i in input().split(' ')]
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + (k - 1) * 2 + smallest_divisor(n))
	tests = tests - 1


def sis(x):
	d = x
	for i in range(2, int(x ** 0.5) + 1):
		if x % i == 0:
			d = i
			break
	return d
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		ans = n + 2 * k
	else:
		new = sis(n)
		ans = n + new + (k - 1) * 2
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	value = 0
	if n % 2 == 0:
		answer = n + k * 2
		print(answer)
		continue
	i = 3
	while i * i <= n:
		if n % i == 0:
			break
		i += 2
	value = i
	if n % i != 0:
		value = n
	answer = n + value + (k - 1) * 2
	print(answer)


def main():
	import sys, math
	from heapq import heapify, heappush, heappop
	from collections import defaultdict as dd, deque, Counter

	def data():
		return sys.stdin.readline().strip()

	def mdata():
		return list(map(int, data().split()))

	def out(*var, end='\n'):
		sys.stdout.write(' '.join(map(str, var)) + end)
	INF = int(1000000000.0)
	mod = int(1000000000.0) + 7
	for i in range(int(data())):
		(n, k) = mdata()
		if n % 2 == 0:
			print(n + 2 * k)
		else:
			t = n
			for i in range(2, int(n ** 0.5) + 1):
				if n % i == 0:
					t = i
					break
			print(n + t + (k - 1) * 2)
main()


def isprime(num):
	if num <= 1:
		return False
	if num <= 3:
		return True
	if num % 2 == 0 or num % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i += 6
	return True

def least_factor(num):
	if isprime(num):
		return num
	else:
		factor = 0
		for i in range(2, num + 1):
			if num % i == 0:
				factor = i
				break
		return factor
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
		continue
	else:
		least = least_factor(n)
		print(n + least + 2 * (k - 1))


t = int(input(''))
u = 0
while u < t:
	(n, k) = [int(n) for n in input().split()]
	e = 0
	while e < k:
		o = []
		if n % 2 != 0:
			for r in range(3, n + 1, 2):
				if n % r == 0:
					o.append(r)
					break
			n = min(o) + n
			e += 1
		else:
			n = n + 2 * (k - e)
			e = k
	print(n)
	u += 1


from collections import deque
t = int(input())
rez = []
for i in range(t):
	A = input().split()
	n = int(A[0])
	k = int(A[1])
	for j in range(k):
		if n % 2 == 0:
			n = n + (k - j) * 2
			break
		for h in range(2, n + 1):
			if n % h == 0:
				break
		n += h
	rez.append(n)
for i in range(len(rez)):
	print(rez[i])


from math import ceil, floor, sqrt
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n
	if n % 2 == 0:
		print(n + 2 * k)
		continue
	i = 1
	li = []
	while i * i <= n:
		if n % i == 0:
			li.append(i)
		if len(li) >= 3:
			break
		i += 1
	if len(li) == 1:
		ans += n
	else:
		ans += li[1]
	print(ans + 2 * (k - 1))


def devisor(n):
	for i in range(3, n + 1, 2):
		if n % i == 0:
			n += i
			break
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = 0
	for i in range(k):
		if n % 2 == 0:
			n += 2 * (k - i)
			break
		else:
			a = devisor(n)
			n = a
	print(n)


def get_min_divisor(num):
	min_divisor = num
	max_divisor = int(round(num ** 0.5, 0))
	for divisor in range(2, max_divisor + 1):
		if num % divisor == 0:
			min_divisor = divisor
			break
	return min_divisor

def update_and_add_minimum_divisor_to_number(num_queries):
	query_number = 0
	while query_number < num_queries:
		addition_data = input()
		addition_data_list = addition_data.split(' ')
		number = int(addition_data_list[0])
		total_additions = int(addition_data_list[1])
		remaining_additions = total_additions
		while remaining_additions > 0:
			min_divisor = get_min_divisor(number)
			if min_divisor == 2:
				number += 2 * remaining_additions
				break
			else:
				number += min_divisor
			remaining_additions -= 1
		print(number)
		query_number += 1
num_queries_user = int(input())
update_and_add_minimum_divisor_to_number(num_queries_user)


from sys import stdin, stdout
for _ in range(int(stdin.readline().strip())):
	(n, k) = list(map(int, stdin.readline().strip().split()))
	if n % 2 == 0:
		stdout.write(str(n + 2 * k) + '\n')
	else:
		for i in range(2, n + 1):
			if n % i == 0:
				stdout.write(str(n + i + 2 * (k - 1)) + '\n')
				break


t = int(input())
l = []
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if n % 2 == 0:
		ans = n + k * 2
	else:
		for j in range(2, n + 2):
			if n % j == 0:
				l.append(j)
				l.sort()
		ans = n + l[0] + (k - 1) * 2
		l.clear()
	print(ans)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	i = 1
	a = list()
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				a.append(i)
			else:
				a.append(i)
				a.append(n // i)
		i = i + 1
	a.remove(1)
	c = min(a)
	ans = n + c
	ans = ans + (k - 1) * 2
	print(ans)


import math as mt
import sys, string
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
t = I()
for _ in range(t):
	(n, k) = M()
	key = -1
	for i in range(2, int(mt.sqrt(n)) + 1):
		if n % i == 0:
			key = i
			break
	if key == -1:
		print(n + n + (k - 1) * 2)
	elif key % 2 == 1:
		print(n + key + (k - 1) * 2)
	else:
		print(n + k * 2)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial, sqrt
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	for _ in range(N()):
		(n, k) = RL()
		res = n
		now = n
		for i in range(k):
			for j in range(2, int(sqrt(now) + 1)):
				if now % j == 0:
					now = j
					break
			if now % 2 == 0:
				res += 2 * (k - i)
				break
			res += now
			now = res
			res = now
		print(res)
main()


class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from bisect import bisect_right, bisect_left
from fractions import Fraction

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans
from math import gcd

def lcm(a, b):
	return a * b // gcd(a, b)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	while k:
		if n % 2 == 0:
			n = n + 2 * k
			k = 0
			break
		else:
			for i in range(2, n + 1):
				if n % i == 0:
					n += i
					k -= 1
					break
	print(n)


from collections import defaultdict as dc
from collections import Counter
from heapq import *
import math
from bisect import bisect_left, bisect
import sys
from collections import deque as dq
from heapq import heapify, heappush, heappop
mod = 10 ** 9 + 7

def sinp():
	p = str(input())
	return p

def seive(n):
	p = [0] * (n + 1)
	for i in range(2, n):
		if p[i] == 0:
			for j in range(2 * i, n + 1, i):
				p[i] = 1
	return p

def inp():
	p = int(input())
	return p

def line():
	p = list(map(int, input().split()))
	return p

def read_mat():
	n = inp()
	a = []
	for i in range(n):
		a.append(line())
	return a

def digit(n):
	s = str(n)
	p = 0
	for i in s:
		p += int(i) ** 2
	return p

def smallest(a):
	if a % 2 == 0:
		return 2
	for i in range(3, int(pow(a, 2)) + 1, 2):
		if a % i == 0:
			return i

def func(x, y, z):
	return 2 ** x * 2 ** y * 2 ** z

def solve(n, k):
	if n % 2 == 0:
		return n + 2 * k
	z = smallest(n)
	return n + z + 2 * (k - 1)
for test in range(inp()):
	(n, k) = line()
	l = solve(n, k)
	print(l)


import math

def factor(num):
	num1 = int(math.sqrt(num)) + 1
	lis = []
	for i in range(1, num1):
		if num % i == 0:
			x1 = num // i
			if i != x1:
				lis.append(i)
				lis.append(x1)
			else:
				lis.append(i)
	lis.sort()
	return lis[1]
t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	if n % 2 == 0:
		n += k * 2
	else:
		x = factor(n)
		n += x
		k -= 1
		n += k * 2
	print(n)


import math
tests = int(input())
lines = [list(map(int, input().split())) for i in range(tests)]

def smallestDivisor(n):
	for divisor in range(3, math.floor(math.sqrt(n)) + 1, 2):
		if n % divisor == 0:
			return divisor
	return n
for line in lines:
	n = line[0]
	k = line[1]
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + smallestDivisor(n) + (k - 1) * 2)


a = []

def smallest_divisor(n):
	for i in range(2, 10 ** 9):
		if n % i == 0:
			break
	return i
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		a.append(n + 2 * k)
	else:
		a.append(n + smallest_divisor(n) + 2 * (k - 1))
for elm in a:
	print(elm)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mod = 1000000007
import math
import bisect
abc = 'abcdefghijklmnopqrstuvwxyz'

def f(n):
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return i
	return n

def main():
	for _ in range(ii()):
		(n, k) = mi()
		if n % 2:
			ans = n + f(n)
			ans += (k - 1) * 2
		else:
			ans = n + k * 2
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if N % 2 == 0:
		t = 2 * K
		print(N + t)
	else:
		t = smallestDivisor(N)
		K = K - 1
		r = 2 * K
		print(N + t + r)


t = int(input())
for i in range(t):
	s = str(input()).split()
	s[0] = int(s[0])
	s[1] = int(s[1])
	while s[1] > 0:
		s[1] -= 1
		if s[0] % 2 == 0:
			s[0] += 2 * (s[1] + 1)
			break
		else:
			c = 1.3333
			for j in range(3, int(s[0] ** 0.5 + 1), 2):
				if s[0] % j == 0:
					c = j
					break
			if s[0] % c == 0:
				s[0] += c
			else:
				s[0] *= 2
	print(s[0])


import sys
input = sys.stdin.readline
import math

def prime(a):
	for i in range(2, int(math.sqrt(a)) + 1):
		if a % i == 0:
			return False
	return True
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if prime(n):
		print(n + n + (k - 1) * 2)
	else:
		for i in range(2, n + 1):
			if n % i == 0:
				pp = i
				pps = n // i
				break
		print(n + pp + (k - 1) * 2)


def divisors(n):
	temp = []
	m = int(n ** 0.5) + 1
	for i in range(1, m):
		if n % i == 0:
			if n // i == i:
				temp.append(i)
			else:
				temp.append(i)
				temp.append(n // i)
	return temp
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		temp = divisors(n)
		temp.sort()
		for i in temp:
			if i != 1 and n % i == 0:
				n += i
				break
		print(n + 2 * (k - 1))


import queue
import math
t = int(input())
while t:
	line = input().split()
	(n, k) = (int(line[0]), int(line[1]))
	if n % 2 == 0:
		print(n + k * 2)
	else:
		k -= 1
		i = 2
		flag = False
		while i * i <= n:
			if n % i == 0:
				flag = True
				break
			i += 1
		if not flag:
			n += n
		else:
			n += i
		print(n + k * 2)
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n & 1:

		def isprime(n):
			if n == 1:
				return 0
			if n == 3 or n == 5 or n == 7:
				return 1
			for i in range(2, int(n ** 0.5) + 1):
				if n % i == 0:
					return 0
			return 1

		def factor(n):
			for i in range(3, int(n ** 0.5) + 1):
				if n % i == 0:
					return i
		if isprime(n):
			print(n + n + 2 * (k - 1))
		else:
			fact = factor(n)
			print(n + fact + 2 * (k - 1))
	else:
		print(n + k * 2)


def process(n, k):
	for i in range(k):
		if n % 2 == 0:
			n += 2 * (k - i)
			break
		else:
			for i in range(3, n + 1, 2):
				if n % i == 0:
					n += i
					break
	print(n)
t = int(input())
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	process(n, k)


import sys
msg = sys.stdin.readlines()
l = []
for i in msg:
	l.append(list(map(int, i.split())))

def orac_f(n, k):
	div = 1
	for i in range(2, n + 1):
		if n % i == 0:
			div = i
			break
	if k == 1:
		return n + div
	else:
		k = k - 1
		n = n + div
		n += k * 2
		return n
for i in l[1:]:
	print(orac_f(i[0], i[1]))


T = int(input())

def sieve(n):
	prime = [0 for i in range(n + 1)]
	visited = [False for i in range(n + 1)]
	p = 2
	while p < n + 1:
		if not visited[p]:
			visited[p] = True
			prime[p] = p
			for i in range(p * 2, n + 1, p):
				if not visited[i]:
					prime[i] = p
					visited[i] = True
		p += 1
	return prime
prime_list = sieve(10 ** 6 + 1)
for t in range(T):
	(n, k) = [int(i) for i in input().split()]
	if n % 2 == 0:
		print(n + k * 2)
	else:
		n += prime_list[n]
		print(n + (k - 1) * 2)


def divisor(n):
	front = []
	back = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			front.append(i)
			if i ** 2 == n:
				continue
			back.append(n // i)
	return front + back[::-1]
a = int(input())
for i in range(a):
	(n, k) = map(int, input().split())
	t = divisor(n)[1]
	if n % 2 != 0:
		print(n + t + (k - 1) * 2)
	else:
		print(n + k * 2)


t = int(input())
for i in range(t):
	(n, k) = [int(i) for i in input().split()]
	f = 2
	while n % f:
		f += 1
	print(n + f + 2 * (k - 1))


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip()
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
test = int(input())

def smallest(n):
	for d in range(2, n + 1):
		if n % d == 0:
			return d
for _ in range(test):
	(n, k) = map(int, input().split())
	if not n & 1:
		print(n + 2 * k)
	else:
		print(n + smallest(n) + 2 * (k - 1))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	d = 2
	while n % d:
		d += 1
	if d == 2:
		print(n + 2 * k)
	elif n % 2:
		print(n + d + (k - 1) * 2)
	elif k <= 2:
		print(n + d * k)
	else:
		print(n + d * 2 + (k - 2) * 2)


t = int(input())
for T in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		var = n
		for x in range(2, n + 1):
			if n % x == 0:
				var = x
				break
		print(n + x + (k - 1) * 2)


def finddiv(num):
	i = 2
	while i < num // 2:
		if num % i == 0:
			return i
		i += 1
	return num
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	i = 0
	while i < k:
		if n % 2 == 0:
			n = n + (k - i) * 2
			break
		n = n + finddiv(n)
		i += 1
	print(n)


import sys, math, cmath, time
start_time = time.time()
tt = 0

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def solve():
	(n, k) = invr()
	for i in range(1, n):
		if n % (i + 1) == 0:
			break
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + (i + 1 + 2 * (k - 1)))

def main():
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
	sys.stdout.close()

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	s = smallestDivisor(n)
	if k == 1:
		print(s + n)
	else:
		a = s + n + 2 * (k - 1)
		print(a)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	k = 0
	f = -1
	if x % 2 == 0:
		k = 2
	else:
		f = 1
		for i in range(2, int(x ** 0.5) + 1):
			if x % i == 0:
				k = i
				f = 0
				break
	if f == 1:
		k = x
	m = y - 1
	x = x + k + 2 * m
	print(x)


x = int(input())
if x >= 1 and x <= 100:
	for i in range(x):
		y = list(input().split())
		n = int(y[0])
		k = int(y[1])
		if n % 2 == 0:
			print(n + 2 * k)
		else:
			for i in range(2, n + 1):
				if n % i == 0:
					n += i
					if k != 1:
						n += 2 * (k - 1)
					break
			print(n)


def solve():
	(n, k) = map(int, input().split())
	d = 0
	while d != 2:
		d = next((i for i in range(2, n + 1) if n % i == 0))
		n += d
		k -= 1
	print(n + k * 2)
for _ in range(int(input())):
	solve()


def factorise(n):
	dic = {}
	while n % 2 == 0:
		if 2 in dic:
			dic[2] += 1
		else:
			dic[2] = 1
		n = n / 2
	for i in range(3, int(n ** 0.5) + 1):
		if n % i == 0:
			if i in dic:
				dic[i] += 1
			else:
				dic[i] = 1
			n = n / i
	if n > 2:
		dic[n] = 1
	return dic
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		dic = factorise(n)
		print(n + min(dic.keys()) + 2 * (k - 1))


t = int(input())

def divisors(n):
	ret = n
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			ret = i
			break
	return ret
for _ in range(t):
	(n, k) = map(int, input().split())
	print(n + divisors(n) + (k - 1) * 2)


from sys import stdin, stdout

def ai():
	return list(map(int, input().split()))

def ei():
	return map(int, input().split())

def ip():
	return int(stdin.readline())

def op(ans):
	return stdout.write(str(ans) + '\n')

def f(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
t = ip()
while t:
	t -= 1
	(n, k) = ei()
	if n % 2 == 0:
		op(2 * k + n)
	else:
		op(f(n) + n + 2 * (k - 1))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		s = n
		for i in range(int(n ** 0.5), 0, -1):
			if n % (n // i) == 0:
				s = min(s, n // i)
			if n % i == 0 and i != 1:
				s = min(s, i)
		s = s + n + 2 * k - 2
		print(s)


i = int(input(''))
t = 0
x = 0
while t < i and i >= 1 and (i <= 100):
	(n, k) = input('').split()
	n = int(n)
	k = int(k)
	if n <= 1000000 and n >= 2 and (k >= 1) and (k <= 1000000000):
		b = n
		for j in range(2, b + 1):
			if n % j == 0:
				n += j
				break
		print(n + 2 * (k - 1))
	t += 1


from sys import stdin
IBUF = iter(stdin.readlines())
input = IBUF.__next__

def f(n, k):
	if n % 2 == 0:
		return n + 2 * k
	else:
		factor = 3
		while factor * factor <= n:
			if n % factor == 0:
				break
			factor += 2
		if factor * factor > n:
			factor = n
		return f(n + factor, k - 1)
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(f(n, k))


def main():

	def fact(num):
		for i in range(2, int(num ** 0.5) + 1):
			if num % i == 0:
				return i
		return num
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		while k:
			if n % 2 == 0:
				print(n + k * 2)
				break
			n += fact(n)
			k -= 1
		else:
			print(n)
main()


def main():
	t = int(input())
	for o in range(t):
		(n, k) = map(int, input().split())
		if n % 2 == 0:
			print(n + 2 * k)
		else:
			p = 0
			for i in range(3, n + 1):
				if n % i == 0:
					p = i
					break
			print(n + p + 2 * (k - 1))
main()


t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	k = int(l[1])
	for i in range(2, n + 1):
		if n % i == 0:
			break
	n += i
	k -= 1
	print(n + 2 * k)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	f = 0
	for a in range(2, n + 1):
		if n % a == 0:
			f = a
			break
	print(n + f + (k - 1) * 2)


import math
t = int(input())
for _ in range(t):
	initial = 0
	(n, k) = map(int, input().split())
	for i in range(2, n + 1):
		if n % i == 0:
			initial = i
			break
	ans = n + initial + (k - 1) * 2
	print(ans)


def firstprime(n):
	for i in range(2, n):
		if n % i == 0:
			return i
	return n

def sol():
	(a, b) = map(int, input().split())
	ans = a
	ans += firstprime(ans)
	ans = ans + 2 * (b - 1)
	print(ans)
for i in range(int(input())):
	sol()


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	(n, k) = mapi()
	f = n
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			f = i
			break
	print(2 * ((n + f) // 2 + k - 1))


from math import sqrt
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	found = False
	ans = 0
	if not n % 2:
		found = True
		ans = n + 2 * k
	else:
		fac = 0
		for i in range(3, int(sqrt(n)) + 1, 2):
			if not n % i:
				found = True
				fac = i
				break
		if not found:
			fac = n
		ans = n + 2 * (k - 1) + fac
	print(ans)


import math
t = int(input())

def findFact(n):
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return i
	return n
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
		continue
	print(n + 2 * (k - 1) + findFact(n))


pri = {}

def Sieve():
	n = 1000000
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	for p in range(n + 1):
		if prime[p]:
			pri[p] = 1
Sieve()
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 0
	for i in pri.keys():
		if n % i == 0:
			ans = i
			break
	ans = i + 2 * (k - 1) + n
	print(ans)


def func(N):
	if N == 1:
		return 1
	elif N % 2 == 0:
		return 2
	else:
		for i in range(3, int(N / 3) + 1):
			if N % i == 0:
				return i
		return N
T = int(input())
for t in range(T):
	[N, K] = list(map(int, input().strip().split()))
	N += func(N)
	N += 2 * (K - 1)
	print(N)


from sys import stdin
import math
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		c = 3
		while True:
			if n % c == 0:
				break
			c += 2
		print(n + c + 2 * (k - 1))


n = int(input())
for _ in range(n):
	(x, y) = map(int, input().split())
	k = 2
	flag = 0
	while k < x // 2 + 1:
		if x % k == 0:
			flag = 2
			break
		k += 1
	if flag == 0:
		x += x
	else:
		x = x + k
	y -= 1
	x += 2 * y
	print(x)


import math
import bisect
T = int(input())
for t in range(T):
	(N, K) = map(int, input().split())
	for n in range(2, N + 1):
		if N % n == 0:
			break
	print(N + n + 2 * (K - 1))


import math

def find(num, k):
	if num % 2 == 0:
		return 2
	else:
		for i in range(3, num + 1):
			if num % i == 0:
				return i
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ad = find(n, k)
	if ad == 2:
		print(n + 2 * k)
	else:
		print(n + ad + (k - 1) * 2)


def factors(n, k):
	if n % 2 == 0:
		return n + 2 * k
	else:
		for i in range(3, n + 1):
			if n % i == 0:
				break
		return factors(n + i, k - 1)
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(factors(n, k))


def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = int(input())
for i in range(t):
	(n, k) = [int(j) for j in input().split()]
	f = smallestDivisor(n)
	n = n + f
	n = n + 2 * (k - 1)
	print(n)


def smallestfactor(ans):
	for i in range(2, ans + 1):
		if ans % i == 0:
			return i
t = int(input())
while t > 0:
	inp = list(map(int, input().split()))
	n = inp[0]
	k = inp[1]
	count = k
	ans = n
	while ans % 2 != 0 and count > 0:
		temp = smallestfactor(ans)
		ans += temp
		count -= 1
	ans += count * 2
	print(ans)
	t -= 1


def find_prime(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def repeatition(a, b):
	if b == 1:
		return a + find_prime(a)
	else:
		return a + find_prime(a) + (b - 1) * 2
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(repeatition(a, b))


def sf(n):
	for x in range(2, n // 2 + 1):
		if n % x == 0:
			return x
	return n

def f(n, k):
	res = n
	if res % 2 == 0:
		print(2 * k + res)
	else:
		res = res + sf(n)
		k -= 1
		res = res + 2 * k
		print(res)
t = int(input())
while t > 0:
	g = list(map(int, input().split()))
	(n, k) = (g[0], g[1])
	f(n, k)
	t -= 1


from sys import stdin
from math import sqrt
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = 1
	for i in range(2, round(sqrt(n)) + 1):
		if n % i == 0:
			l = i
			break
	if l == 1:
		l = n
	print(n + l + (k - 1) * 2)


import math as m

def isPrime(num):
	k = 2
	rrt = m.sqrt(num)
	while k <= rrt:
		if num % k == 0:
			return False
		k += 1
	return True

def firstDiv(num):
	k = 2
	rrt = m.sqrt(num)
	while k <= rrt:
		if num % k == 0:
			return k
		k += 1
	return -1
t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	if isPrime(n):
		print(n * 2 + (k - 1) * 2)
	else:
		first = firstDiv(n)
		print(n + first + (k - 1) * 2)


t = int(input())
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if n % 2 == 0:
		n += 2 * k
		print(n)
	else:
		i = n
		add = 0
		while i >= 2:
			if n % i == 0:
				add = i
			i -= 1
		print(n + add + 2 * (k - 1))


import math
from collections import Counter, deque
L = lambda : list(map(int, input().split()))
M = lambda : map(int, input().split())
I = lambda : int(input())
IN = lambda : input()
mod = 10 ** 9 + 7

def s(a):
	print(' '.join(list(map(str, a))))
for i in range(I()):
	(n, k) = M()
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		for i in range(2, n + 1):
			if n % i == 0:
				break
		print(n + i + 2 * (k - 1))


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(n, k) = list(map(int, stdin.readline().split()))
	k += 1
	if n & 1:
		p = 2
		f = 0
		while p * p <= n:
			if n % p == 0:
				f = 1
				break
			p += 1
		if f == 0:
			p = n
		n += p
		k -= 1
	print(n + (k - 1) * 2)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	p = 2
	while p ** 2 <= n:
		if not n % p:
			n += p
			break
		p += 1
	else:
		n *= 2
	print(n + (k - 1) * 2)


t = int(input())
for test in range(t):
	(n, k) = list(map(int, input().split()))
	if n % 2 == 0:
		ans = n + 2 * k
		print(ans)
	else:
		for i in range(2, n + 1):
			if n % i == 0:
				ans = n + i
				break
		ans += 2 * (k - 1)
		print(ans)


from math import sqrt

def solve(n, k):
	if n % 2 == 0:
		return n + 2 * k
	sqrt_n = int(sqrt(n))
	fn = 1
	for d in range(3, sqrt_n + 1, 2):
		if n % d == 0:
			fn = d
			break
	if fn == 1:
		fn = n
	return n + fn + 2 * (k - 1)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print(solve(n, k))


def fun(n):
	i = 2
	x = 1
	while i * i <= n:
		if n % i == 0:
			x = i
			break
		i += 1
	return x
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		x = fun(n)
		if x == 1:
			n += n
		else:
			n += x
		print(n + 2 * (k - 1))


import sys
import math as mt
input = sys.stdin.buffer.readline
import bisect
t = int(input())
for __ in range(t):
	(n, k) = map(int, input().split())
	for i in range(2, n + 1):
		if n % i == 0:
			sd = i
			break
	ans = n + i
	ans += 2 * (k - 1)
	print(ans)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 1:
		temp = 0
		for i in range(2, math.ceil(math.sqrt(n)) + 1):
			if n % i == 0:
				n += i
				k -= 1
				temp = 1
				break
		if temp == 0:
			n += n
			k -= 1
	print(n + k * 2)


t = int(input())

def sd(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	first = sd(n)
	n += first + 2 * (k - 1)
	print(n)


def f(n):
	i = 2
	while True:
		if n % i == 0:
			return i
		else:
			i = i + 1
t = int(input())
final = []
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	answer = n + f(n) + 2 * (k - 1)
	final.append(answer)
for k in final:
	print(k)


import sys
input = iter(sys.stdin.readlines()).__next__
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	for f in range(2, n + 1):
		if n % f == 0:
			break
	n += f + 2 * (k - 1)
	print(n)


import math
t = int(input())
lst = []
for i in range(t):
	lst.append([p for p in map(int, input().split(' '))])
for a in lst:
	n = a[0]
	k = a[1]
	i = 2
	while i <= n:
		if n / i % 1 == 0:
			break
		i += 1
	n += i + 2 * (k - 1)
	print(n)


import math

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def get_d(i):
	t = 2
	while t * t <= i:
		if i % t == 0:
			return t
		t += 1
	return i

def solve():
	(n, k) = Read.list_int()
	res = 0
	l = 0
	for i in range(k):
		l += 1
		res = n + get_d(n)
		if res % 2 == 0:
			res += (k - l) * 2
			print(res)
			return
	print(res)
query_count = Read.int()
while query_count:
	query_count -= 1
	solve()


from math import *
t = int(input())
m = []
n = []
for i in range(t):
	x = list(map(int, input().split()))
	m.append(x)
for i in range(t):
	n = m[i][0]
	for k in range(n - 1):
		if n % (k + 2) == 0:
			l = k + 2
			n = n + l + 2 * (m[i][1] - 1)
			break
	print(n)


import math as m

def cp(n):
	z = a
	for i in range(2, int(m.sqrt(a)) + 1):
		if a % i == 0:
			z = i
			break
	return z
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	q = cp(a)
	print(a + q + 2 * (b - 1))


import sys

def smallest(n):
	for i in range(2, n // 2 + 1):
		if (n / i).is_integer():
			return i
	return n

def smallest_repeat(n, k):
	s = smallest(n)
	n += s
	if k == 1:
		return n
	return n + smallest(n) * (k - 1)
lines = sys.stdin.read().split()
t = int(lines[0])
for i in range(1, len(lines), 2):
	(n, k) = (int(lines[i]), int(lines[i + 1]))
	print(smallest_repeat(n, k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	elif n % 3 == 0:
		print(n + 3 + 2 * (k - 1))
	else:
		i = 5
		f = 0
		while i * i <= n:
			if n % i == 0:
				f = 1
				break
			i += 1
		if f:
			print(n + i + 2 * (k - 1))
		else:
			print(n + n + 2 * (k - 1))


import math

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		n = n + 2 * k
		print(n)
	else:
		L1 = Divisors(n)
		L1.remove(1)
		a = min(L1)
		if k > 1:
			n = n + a + 2 * (k - 1)
		else:
			n = n + a
		print(n)


n = int(input())
for i in range(n):
	a = list(map(int, input().strip().split()))
	k = a[0]
	v = a[1]
	f = k
	g = []
	if k % 2 == 0:
		print(k + 2 * v)
	else:
		p = 0
		for i in range(k, 1, -1):
			if k % i == 0:
				p = i
		print(k + p + (v - 1) * 2)


MOD = 10 ** 9 + 7
INT_MAX = 10 ** 20 + 7

def INPUT():
	return list((int(i) for i in input().split()))

def LIST_1D_ARRAY(n):
	return [0 for _ in range(n)]

def LIST_2D_ARRAY(m, n):
	return [[0 for _ in range(n)] for _ in range(m)]

def power(a, x):
	res = 1
	while x > 0:
		if x & 1:
			res = res * a % MOD
		a = a * a % MOD
		x //= 2
	return res % MOD

def NCR_MOD(n, r):
	num = 1
	for i in range(n, n - r, -1):
		num = num * i % MOD
	for j in range(1, r + 1):
		num = num * power(j, MOD - 2) % MOD
	return num
import math as M

def F(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i

def calc(n, k):
	return n + F(n) + (k - 1) * 2
for _ in range(int(input())):
	(a, b) = INPUT()
	print(calc(a, b))


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	m = 0
	(n, k) = map(int, stdin.readline().split())
	for i in range(2, n + 1):
		if n % i == 0:
			m = i
			break
	ans = 2 * (k - 1)
	ans = ans + (n + m)
	stdout.write(str(ans) + '\n')


def divisor(n):
	a = []
	for i in range(2, n + 1):
		if n % i == 0:
			a.append(i)
		if len(a) > 0:
			break
	a.sort()
	return a[0]
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	z = divisor(a)
	a = a + z
	if z % 2 != 0:
		a = a + 2 * (b - 1)
	else:
		a = a + z * (b - 1)
	print(a)


from math import sqrt

def small(n):
	i = 1
	for i in range(2, int(sqrt(n)) + 2):
		if n % i == 0:
			return i
	return n
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	q = small(n)
	ans = n + q
	if k == 0:
		print(n)
	if k == 1:
		print(n + q)
	else:
		print(ans + 2 * (k - 1))


def divisor(n):
	d = 0
	for i in range(2, n // 2 + 1):
		if n % i == 0:
			d = i
			break
	if d:
		return d
	return n
n = int(input())
for i in range(0, n):
	(x, y) = [int(a) for a in input().split()]
	if x % 2 == 0:
		s = x + 2 * y
	else:
		d = divisor(x)
		s = x + d + 2 * (y - 1)
	print(s)


def findDiv(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return i
	return n
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		ans = n + k * 2
	else:
		a = findDiv(n)
		ans = n + a + (k - 1) * 2
	print(ans)


def shortestFactor(n):
	num = 0
	for i in range(3, n + 1):
		if n % i == 0:
			num = i
			break
	return num

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		ans = 0
		while k > 0:
			if n % 2 == 0:
				ans = n + 2 * k
				break
			else:
				s = shortestFactor(n)
				ans += s + n
				n = s + n
			k -= 1
		print(ans)
main()


import math

class A:

	def solve(self):
		t = int(input())

		def smallest_divisor(n):
			sqrt_n = math.sqrt(n)
			for i in range(2, int(sqrt_n) + 1, 1):
				if n % i == 0:
					return i
			return n

		def query(n, k):
			if k == 0:
				return n
			elif n % 2 == 0:
				return n + 2 * k
			return query(n + smallest_divisor(n), k - 1)
		for p in range(t):
			(n, k) = tuple(map(int, input().split(' ')))
			print(query(n, k))
A().solve()


import sys
I = sys.stdin.readline
ans = ''

def is_prime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return i
	return 0
for _ in range(int(I())):
	(n, k) = map(int, I().split())
	if n % 2 != 0:
		flag = is_prime(n)
		if flag == 0:
			x = 2 * n + (k - 1) * 2
		else:
			x = n + flag + (k - 1) * 2
	else:
		x = n + k * 2
	ans += str(x) + '\n'
print(ans)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def divisor(n):
	ret = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i != 1:
				ret.append(i)
			if i * i != n:
				ret.append(n // i)
	return ret

def solve():
	(n, k) = map(int, input().split())
	a = divisor(n)
	a.sort()
	s = 2
	if n % 2 == 1:
		n += a[0]
		k -= 1
	n += 2 * k
	print(n)
t = int(input())
for i in range(t):
	solve()


def f(n):
	a = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			a.append(i)
			a.append(n // i)
	a.remove(1)
	b = min(a)
	return n + b
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(f(n) + 2 * (k - 1))


T = int(input())
for _ in range(T):
	(n, k) = list(map(int, input().split()))
	for r in range(2, n + 1):
		if n % r == 0:
			break
	ans = n + r + 2 * (k - 1)
	print(ans)


t = int(input())
results = []
for case in range(t):
	(n, k) = map(int, input().split())
	for i in range(2, n + 1):
		if n % i == 0:
			n += i
			break
	n += (k - 1) * 2
	results.append(n)
for result in results:
	print(result)


def check(n):
	j = n
	for k in range(2, int(n / 2) + 1):
		if n % k == 0:
			j = k
			break
	return j
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + check(n) + 2 * (k - 1))


from math import *

def d(n):
	ans = n
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			ans = min(ans, i, n // i)
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(n + d(n) + 2 * (k - 1))


import math
t = int(input())
while t:
	(n, k) = map(int, input().split())
	i = 2
	fac = n
	while i <= math.sqrt(n):
		if n % i == 0:
			fac = i
			break
		i += 1
	if n % 2 == 0:
		n = n + 2 * k
	else:
		n = n + fac + 2 * (k - 1)
	print(n)
	t -= 1


from math import sqrt

def devisor(n):
	for i in range(2, int(sqrt(n) + 1)):
		if n % i == 0:
			return i
	return n
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		deviso = devisor(n)
		if k == 1:
			print(n + deviso)
		else:
			while k:
				k = k - 1
				if (deviso + n) % 2 == 0:
					print(n + deviso + k * 2)
					break
				else:
					deviso = devisor(n + deviso)


from math import sqrt
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	f = 2
	flag = True
	while f <= sqrt(n):
		if n % f == 0:
			n += f
			flag = False
			break
		f += 1
	if flag:
		n += n
	k -= 1
	t = k * 2
	n = n + t
	print(n)


from math import *
from collections import *
from itertools import *
from bisect import *
from operator import *
import sys
sys.setrecursionlimit(1000000)

def io():
	return map(int, input().split())

def op():
	return list(map(int, input().split()))

def o():
	return int(input())

def kl(con, x=0):
	if x == 0:
		print('Yes') if con else print('No')
	elif x == 1:
		print('yes') if con else print('no')
	elif x == 2:
		print('YES') if con else print('NO')
p = input
for _ in range(o()):
	(a, b) = io()
	for i in range(2, a + 1):
		if a % i == 0:
			a += i
			break
	b -= 1
	a += 2 * b
	print(a)


t = int(input())
ft = dict()

def f(n):
	if n % 2 == 0:
		return 2
	if n % 3 == 0:
		return 3
	i = 5
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for _ in range(t):
	(n, k) = map(int, input().split())
	n += f(n)
	n += 2 * (k - 1)
	print(n)


t = int(input())
List = [list(map(int, input().split())) for i in range(t)]
ans = 0
for i in range(t):
	ans = List[i][0]
	if List[i][0] % 2 == 0:
		print(int(List[i][0]) + 2 * int(List[i][1]))
	else:
		j = 3
		while List[i][0] % j != 0:
			j += 1
		print(List[i][0] + j + 2 * int(List[i][1] - 1))


def task(n, k):
	divisor = 0
	for i in range(0, k):
		if n % 2 == 0:
			n += (k - i) * 2
			break
		for i in range(2, n + 1):
			if n % i == 0:
				divisor = i
				break
		n += divisor
	print(n)
t = int(input())
for i in range(0, t):
	(n, k) = map(int, input().split())
	task(n, k)


for _ in range(int(input())):
	n = [int(i) for i in input().split()]
	a = n[0]
	b = n[1]
	c = 0
	if a % 2 == 0:
		print(a + b * 2)
		continue
	for e in range(3, a + 1, 2):
		if e * e <= a:
			if a % e == 0:
				print(a + e + (b - 1) * 2)
				break
		else:
			print(a * 2 + (b - 1) * 2)
			break


z = input

def q(n):
	x = int(n ** 0.5) + 2
	c = 0
	g = n
	for j in range(2, x):
		if n % j == 0:
			c = 1
			r = j
			break
	if c == 0:
		r = n
	return r + g
ml = int(z())
for i in range(ml):
	(a, b) = map(int, z().split())
	t = q(a)
	print(t + (b - 1) * 2)


for _ in range(int(input())):
	(n, k) = [int(__) for __ in input().split()]
	f_n = n
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			f_n = i
			break
	if f_n != 2:
		print(n + f_n + (k - 1) * 2)
	else:
		print(n + k * f_n)


import math
T = int(input())
n = [0] * T
k = [0] * T
for t in range(T):
	(n[t], k[t]) = [int(i) for i in input().split(' ')]

def f(x, d=0):
	if d:
		return 2
	for i in range(2, int(x ** 0.5) + 1):
		if x % i == 0:
			return i
	return x
for t in range(T):
	d = False
	if f(n[t]) == n[t]:
		d = True
	d1 = False
	for i in range(k[t]):
		n[t] = n[t] + f(n[t], d1)
		if d:
			d1 = True
		if f(n[t], d1) == 2:
			n[t] += (k[t] - i - 1) * 2
			break
	print(n[t])


from math import sqrt
for T in range(int(input())):
	(n, k) = list(map(int, input().split()))
	temp = n
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			temp = i
			break
	n += temp
	n += (k - 1) * 2
	print(n)


def minitem(a):
	b = 0
	for i in range(2, a + 1):
		if a % i == 0:
			b = i
			break
	return b
n = int(input())
for i in range(n):
	s = input().split(' ')
	m = int(s[0])
	k = int(s[1])
	u = minitem(m)
	if u == 2:
		print(m + u * k)
	else:
		while m % 2 != 0 and k > 0:
			m += u
			k -= 1
		print(m + k * 2)


from math import sqrt
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		n += 2 * k
	elif n % 2 != 0:
		q = int(sqrt(n))
		for j in range(3, q + 1, 2):
			if n % j == 0:
				x = j
				break
		else:
			x = n
		n += x + 2 * (k - 1)
	print(n)


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().strip().split()))

	def second(a):
		for i in range(2, a + 1):
			if a % i == 0:
				b = i
				break
			else:
				continue
		return b
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		fn = second(n)
		print(n + fn + 2 * (k - 1))


import sys
import math
from collections import deque
input = sys.stdin.buffer.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	minF = 0
	for i in range(2, n + 1):
		if n % i == 0:
			minF = i
			break
	n += minF
	n += 2 * (k - 1)
	print(n)


import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def primeFactors(n):
	while n % 2 == 0:
		return 2
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			return i
			n = n // i
	if n > 2:
		return n

def solve():
	(n, k) = num_input()
	num = primeFactors(n)
	k -= 1
	n += num
	print(n + 2 * k)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	x = 0
	while n % 2 != 0 and x < k:
		for i in range(3, n + 1):
			if n % i == 0:
				break
		n += i
		x += 1
	print(n + 2 * (k - x))


import collections
from math import sqrt

def solve(n, k):
	ans = n
	for div in range(2, int(sqrt(n)) + 2):
		if n % div == 0:
			ans = div
			break
	return n + ans + (k - 1) * 2
t = int(input().strip())
for i in range(t):
	[n, k] = list(map(int, input().strip().split()))
	print(solve(n, k))


from collections import Counter
import math
mod = 10 ** 9 + 7
for i in range(int(input())):
	(n, k) = map(int, input().split())
	for i in range(2, n + 1):
		if n % i == 0:
			x = i
			k -= 1
			break
	x += 2 * k
	print(x + n)


def f(n, k):
	divi = []
	if n % 2 == 0:
		print(n + 2 * k)
	elif n % 2 == 1:
		for j in range(2, n + 1):
			if n % j == 0:
				divi.append(j)
		print(n + divi[0] + 2 * (k - 1))
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	f(n, k)


def solve():
	ans = n + find_smallest(n)
	ans += (k - 1) * 2
	print(ans)
	return

def find_smallest(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
t = int(input())
for i in range(1, t + 1):
	(n, k) = [int(i) for i in input().split(' ')]
	solve()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		n += k * 2
	else:
		for l in range(3, n + 1, 2):
			if n % l == 0:
				n += l
				break
		n += (k - 1) * 2
	print(n)


from math import sqrt

def divs(n):
	a = []
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if n // i == i:
				a.append(i)
			else:
				a += [i, n // i]
	return sorted(a)[1]
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		f = n
		while f % 2 != 0 and k > 0:
			f = divs(n) + n
			k -= 1
		print(f + 2 * k)


for nt in range(int(input())):
	(n, k) = map(int, input().split())
	for i in range(2, n + 1):
		if n % i == 0:
			num = i
			break
	print(n + i + 2 * (k - 1))


def f(n):
	for i in range(2, int(n ** 0.5 + 1)):
		if n % i == 0:
			return i
	return n
num_lines = int(input())
lineList = []
for i in range(num_lines):
	lineList.append([int(i) for i in input().split()])
for inp in lineList:
	daude = f(inp[0])
	flag = False
	num = inp[0]
	num += daude
	num_iters = inp[1] - 1
	print(num + num_iters * 2)


from math import sqrt
a = int(input())
for _ in range(a):
	(b, c) = map(int, input().split())
	i = 2
	while i <= sqrt(b + 1):
		if b % i == 0:
			b = b + i
			break
		i += 1
	if i > sqrt(b + 1):
		b += b
	print(b + (c - 1) * 2)


def solve(n):
	div = 0
	for i in range(7, int(n ** 0.5) + 1):
		if n % i == 0:
			div = i
			break
	if div == 0:
		div = n
	return div
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	elif n % 3 == 0:
		print(n + 3 + (k - 1) * 2)
	elif n % 5 == 0:
		print(n + 5 + (k - 1) * 2)
	elif n % 7 == 0:
		print(n + 7 + (k - 1) * 2)
	else:
		res = solve(n)
		n += res
		print(n + 2 * (k - 1))


a = int(input())
while a > 0:
	l = list(map(int, input().split(' ')))
	s = l[0]
	k = 0
	s1 = 0
	for i in range(2, s + 1):
		if s % i == 0:
			k = i
			break
	s = s + k + (l[1] - 1) * 2
	print(s)
	a = a - 1


import math

def find_dividers(x):
	dividers = []
	dividers.append(x)
	for i in range(2, int(math.sqrt(x) + 1)):
		if x % i == 0:
			dividers.append(i)
			break
	return dividers
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * m)
	else:
		minimum = min(find_dividers(n))
		print(n + minimum + (m - 1) * 2)


t = int(input())
for i10 in range(t):
	(n, k) = map(int, input().split())
	c = 2
	while 1 == 1 and c <= n:
		if n % 2 == 0:
			break
		elif n % c == 0:
			k -= 1
			n += c
		c += 1
	n = n + k * 2
	print(n)


import math
for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	d = 0
	for i in range(2, n + 1):
		d = i
		if n % i == 0:
			break
	print(2 * (k - 1) + d + n)


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	for j in range(2, a + 1):
		if a % j == 0:
			kek = j
			break
	a += kek
	a += 2 * (b - 1)
	print(a)


from collections import deque

def prime_flag():
	ans = deque()
	li = [True] * 1005
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			ans.append(i)
			for j in range(i * i, len(li), i):
				li[j] = False
	return ans

def solve(li):
	(n, k) = [int(x) for x in input().split()]
	if n % 2 == 0:
		div = 2
	else:
		for ele in li:
			if n % ele == 0:
				div = ele
				break
		else:
			div = n
	n = div + n
	k -= 1
	print(2 * k + n)
	return
t = int(input())
li = prime_flag()
for i in range(t):
	solve(li)


import math

def findPrime(x):
	for i in range(2, x + 1):
		if x % i == 0:
			return i
	return 0

def solve():
	(n, k) = [int(x) for x in input().split()]
	out = 0
	for _ in range(1, k + 1):
		out = _
		n += findPrime(n)
		if n % 2 == 0:
			break
	n += (k - out) * 2
	print(n)
nums = int(input())
for _ in range(1, nums + 1):
	solve()


t = int(input())
for i in range(t):
	(n, k) = [int(i) for i in input().split()]
	list1 = 0
	while k != 0 and n % 2 != 0:
		for i in range(3, n + 1):
			if n % i == 0:
				n = n + i
				break
		k -= 1
	n = n + 2 * k
	print(n)


def fst(x):
	if x % 2 == 0:
		return 2
	for k in range(3, 1000, 2):
		if x % k == 0:
			return k
	return x
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(n + fst(n) + 2 * (k - 1))


import math
for t in range(int(input())):
	(n, k) = map(int, input().split())
	x = math.sqrt(n)
	s = n
	f = 0
	for i in range(2, int(x) + 1):
		if n % i == 0:
			f = 1
			s += i
			break
	if f == 0:
		s += n
	s += (k - 1) * 2
	print(s)


I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n, k) = I()
	if n % 2 == 0:
		print(n + 2 * k)
		continue
	i = 3
	while 1:
		if n % i == 0:
			print(n + i + 2 * (k - 1))
			break
		i += 2


try:
	T = int(input())
	for i in range(T):
		(n, k) = input().split()
		n = int(n)
		k = int(k)
		if n % 2 == 0:
			n = n + 2 * k
			print(n)
		else:
			for j in range(2, n + 1):
				if n % j == 0:
					n = n + j
					break
			n = n + 2 * (k - 1)
			print(n)
except Exception as e:
	print(e)


def f(a):
	if a == 1:
		return 1
	for f1 in range(2, a + 1, 1):
		if a % f1 == 0:
			return f1
t = int(input())
for i1 in range(t):
	(n, k) = list(map(int, input().split()))
	temp = f(n)
	print(n + temp + 2 * (k - 1))


try:
	t = int(input())
	for i in range(t):
		a = input().split()
		n = int(a[0])
		k = int(a[1])
		if n % 2 == 0:
			print(n + k * 2)
		else:
			for j in range(3, n + 1):
				if n % j == 0:
					n += j
					break
			print(n + (k - 1) * 2)
except EOFError:
	exit(0)


def f(a):
	b = 2
	while a % b > 0:
		b += 1
	return b
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	if not n % 2:
		print(n + 2 * k)
		continue
	x = f(n)
	print(n + x + 2 * (k - 1))


def f(x):
	if x % 2 == 0:
		return 2
	i = 3
	val = x
	while i * i <= x:
		if x % i == 0:
			val = i
			break
		else:
			i += 2
	return val
t = int(input())
for i in range(0, t):
	l = list(map(int, input().split()))
	n = l[0]
	k = l[1]
	print(n + f(n) + 2 * (k - 1))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	s = n
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		j = 3
		while n % j != 0:
			j = j + 2
		n = n + j
		print(n + 2 * (k - 1))


import math as mt
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n & 1:
		done = False
		for i in range(2, int(mt.sqrt(n)) + 1):
			if n % i == 0:
				n += i
				k -= 1
				done = True
				break
		if done == False:
			n += n
			k -= 1
	n += 2 * k
	print(n)


T = int(input())
for tc in range(T):
	(n, k) = map(int, input().split())
	lcd = 1
	for i in range(2, n // 2 + 1):
		if n % i == 0:
			lcd = i
			break
	if lcd == 1:
		lcd = n
	n = n + lcd
	res = n + 2 * (k - 1)
	print(res)


def foo(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = int(input())
for i in range(t):
	nk = list(map(int, input().split()))
	n = nk[0]
	k = nk[1]
	if k == 1:
		print(n + foo(n))
	else:
		ans = n + foo(n)
		ans = ans + 2 * (k - 1)
		print(ans)


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919, 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, 8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, 8117, 8123, 8147, 8161, 8167, 8171, 8179, 8191, 8209, 8219, 8221, 8231, 8233, 8237, 8243, 8263, 8269, 8273, 8287, 8291, 8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, 8389, 8419, 8423, 8429, 8431, 8443, 8447, 8461, 8467, 8501, 8513, 8521, 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, 8599, 8609, 8623, 8627, 8629, 8641, 8647, 8663, 8669, 8677, 8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, 8737, 8741, 8747, 8753, 8761, 8779, 8783, 8803, 8807, 8819, 8821, 8831, 8837, 8839, 8849, 8861, 8863, 8867, 8887, 8893, 8923, 8929, 8933, 8941, 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, 9013, 9029, 9041, 9043, 9049, 9059, 9067, 9091, 9103, 9109, 9127, 9133, 9137, 9151, 9157, 9161, 9173, 9181, 9187, 9199, 9203, 9209, 9221, 9227, 9239, 9241, 9257, 9277, 9281, 9283, 9293, 9311, 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, 9391, 9397, 9403, 9413, 9419, 9421, 9431, 9433, 9437, 9439, 9461, 9463, 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533, 9539, 9547, 9551, 9587, 9601, 9613, 9619, 9623, 9629, 9631, 9643, 9649, 9661, 9677, 9679, 9689, 9697, 9719, 9721, 9733, 9739, 9743, 9749, 9767, 9769, 9781, 9787, 9791, 9803, 9811, 9817, 9829, 9833, 9839, 9851, 9857, 9859, 9871, 9883, 9887, 9901, 9907, 9923, 9929, 9931, 9941, 9949, 9967, 9973, 10007, 10009, 10037, 10039, 10061, 10067, 10069, 10079, 10091, 10093, 10099, 10103, 10111, 10133, 10139, 10141, 10151, 10159, 10163, 10169, 10177, 10181, 10193, 10211, 10223, 10243, 10247, 10253, 10259, 10267, 10271, 10273, 10289, 10301, 10303, 10313, 10321, 10331, 10333, 10337, 10343, 10357, 10369, 10391, 10399, 10427, 10429, 10433, 10453, 10457, 10459, 10463, 10477, 10487, 10499, 10501, 10513, 10529, 10531, 10559, 10567, 10589, 10597, 10601, 10607, 10613, 10627, 10631, 10639, 10651, 10657, 10663, 10667, 10687, 10691, 10709, 10711, 10723, 10729, 10733, 10739, 10753, 10771, 10781, 10789, 10799, 10831, 10837, 10847, 10853, 10859, 10861, 10867, 10883, 10889, 10891, 10903, 10909, 10937, 10939, 10949, 10957, 10973, 10979, 10987, 10993, 11003, 11027, 11047, 11057, 11059, 11069, 11071, 11083, 11087, 11093, 11113, 11117, 11119, 11131, 11149, 11159, 11161, 11171, 11173, 11177, 11197, 11213, 11239, 11243, 11251, 11257, 11261, 11273, 11279, 11287, 11299, 11311, 11317, 11321, 11329, 11351, 11353, 11369, 11383, 11393, 11399, 11411, 11423, 11437, 11443, 11447, 11467, 11471, 11483, 11489, 11491, 11497, 11503, 11519, 11527, 11549, 11551, 11579, 11587, 11593, 11597, 11617, 11621, 11633, 11657, 11677, 11681, 11689, 11699, 11701, 11717, 11719, 11731, 11743, 11777, 11779, 11783, 11789, 11801, 11807, 11813, 11821, 11827, 11831, 11833, 11839, 11863, 11867, 11887, 11897, 11903, 11909, 11923, 11927, 11933, 11939, 11941, 11953, 11959, 11969, 11971, 11981, 11987, 12007, 12011, 12037, 12041, 12043, 12049, 12071, 12073, 12097, 12101, 12107, 12109, 12113, 12119, 12143, 12149, 12157, 12161, 12163, 12197, 12203, 12211, 12227, 12239, 12241, 12251, 12253, 12263, 12269, 12277, 12281, 12289, 12301, 12323, 12329, 12343, 12347, 12373, 12377, 12379, 12391, 12401, 12409, 12413, 12421, 12433, 12437, 12451, 12457, 12473, 12479, 12487, 12491, 12497, 12503, 12511, 12517, 12527, 12539, 12541, 12547, 12553, 12569, 12577, 12583, 12589, 12601, 12611, 12613, 12619, 12637, 12641, 12647, 12653, 12659, 12671, 12689, 12697, 12703, 12713, 12721, 12739, 12743, 12757, 12763, 12781, 12791, 12799, 12809, 12821, 12823, 12829, 12841, 12853, 12889, 12893, 12899, 12907, 12911, 12917, 12919, 12923, 12941, 12953, 12959, 12967, 12973, 12979, 12983, 13001, 13003, 13007, 13009, 13033, 13037, 13043, 13049, 13063, 13093, 13099, 13103, 13109, 13121, 13127, 13147, 13151, 13159, 13163, 13171, 13177, 13183, 13187, 13217, 13219, 13229, 13241, 13249, 13259, 13267, 13291, 13297, 13309, 13313, 13327, 13331, 13337, 13339, 13367, 13381, 13397, 13399, 13411, 13417, 13421, 13441, 13451, 13457, 13463, 13469, 13477, 13487, 13499, 13513, 13523, 13537, 13553, 13567, 13577, 13591, 13597, 13613, 13619, 13627, 13633, 13649, 13669, 13679, 13681, 13687, 13691, 13693, 13697, 13709, 13711, 13721, 13723, 13729, 13751, 13757, 13759, 13763, 13781, 13789, 13799, 13807, 13829, 13831, 13841, 13859, 13873, 13877, 13879, 13883, 13901, 13903, 13907, 13913, 13921, 13931, 13933, 13963, 13967, 13997, 13999, 14009, 14011, 14029, 14033, 14051, 14057, 14071, 14081, 14083, 14087, 14107, 14143, 14149, 14153, 14159, 14173, 14177, 14197, 14207, 14221, 14243, 14249, 14251, 14281, 14293, 14303, 14321, 14323, 14327, 14341, 14347, 14369, 14387, 14389, 14401, 14407, 14411, 14419, 14423, 14431, 14437, 14447, 14449, 14461, 14479, 14489, 14503, 14519, 14533, 14537, 14543, 14549, 14551, 14557, 14561, 14563, 14591, 14593, 14621, 14627, 14629, 14633, 14639, 14653, 14657, 14669, 14683, 14699, 14713, 14717, 14723, 14731, 14737, 14741, 14747, 14753, 14759, 14767, 14771, 14779, 14783, 14797, 14813, 14821, 14827, 14831, 14843, 14851, 14867, 14869, 14879, 14887, 14891, 14897, 14923, 14929, 14939, 14947, 14951, 14957, 14969, 14983, 15013, 15017, 15031, 15053, 15061, 15073, 15077, 15083, 15091, 15101, 15107, 15121, 15131, 15137, 15139, 15149, 15161, 15173, 15187, 15193, 15199, 15217, 15227, 15233, 15241, 15259, 15263, 15269, 15271, 15277, 15287, 15289, 15299, 15307, 15313, 15319, 15329, 15331, 15349, 15359, 15361, 15373, 15377, 15383, 15391, 15401, 15413, 15427, 15439, 15443, 15451, 15461, 15467, 15473, 15493, 15497, 15511, 15527, 15541, 15551, 15559, 15569, 15581, 15583, 15601, 15607, 15619, 15629, 15641, 15643, 15647, 15649, 15661, 15667, 15671, 15679, 15683, 15727, 15731, 15733, 15737, 15739, 15749, 15761, 15767, 15773, 15787, 15791, 15797, 15803, 15809, 15817, 15823, 15859, 15877, 15881, 15887, 15889, 15901, 15907, 15913, 15919, 15923, 15937, 15959, 15971, 15973, 15991, 16001, 16007, 16033, 16057, 16061, 16063, 16067, 16069, 16073, 16087, 16091, 16097, 16103, 16111, 16127, 16139, 16141, 16183, 16187, 16189, 16193, 16217, 16223, 16229, 16231, 16249, 16253, 16267, 16273, 16301, 16319, 16333, 16339, 16349, 16361, 16363, 16369, 16381, 16411, 16417, 16421, 16427, 16433, 16447, 16451, 16453, 16477, 16481, 16487, 16493, 16519, 16529, 16547, 16553, 16561, 16567, 16573, 16603, 16607, 16619, 16631, 16633, 16649, 16651, 16657, 16661, 16673, 16691, 16693, 16699, 16703, 16729, 16741, 16747, 16759, 16763, 16787, 16811, 16823, 16829, 16831, 16843, 16871, 16879, 16883, 16889, 16901, 16903, 16921, 16927, 16931, 16937, 16943, 16963, 16979, 16981, 16987, 16993, 17011, 17021, 17027, 17029, 17033, 17041, 17047, 17053, 17077, 17093, 17099, 17107, 17117, 17123, 17137, 17159, 17167, 17183, 17189, 17191, 17203, 17207, 17209, 17231, 17239, 17257, 17291, 17293, 17299, 17317, 17321, 17327, 17333, 17341, 17351, 17359, 17377, 17383, 17387, 17389, 17393, 17401, 17417, 17419, 17431, 17443, 17449, 17467, 17471, 17477, 17483, 17489, 17491, 17497, 17509, 17519, 17539, 17551, 17569, 17573, 17579, 17581, 17597, 17599, 17609, 17623, 17627, 17657, 17659, 17669, 17681, 17683, 17707, 17713, 17729, 17737, 17747, 17749, 17761, 17783, 17789, 17791, 17807, 17827, 17837, 17839, 17851, 17863, 17881, 17891, 17903, 17909, 17911, 17921, 17923, 17929, 17939, 17957, 17959, 17971, 17977, 17981, 17987, 17989, 18013, 18041, 18043, 18047, 18049, 18059, 18061, 18077, 18089, 18097, 18119, 18121, 18127, 18131, 18133, 18143, 18149, 18169, 18181, 18191, 18199, 18211, 18217, 18223, 18229, 18233, 18251, 18253, 18257, 18269, 18287, 18289, 18301, 18307, 18311, 18313, 18329, 18341, 18353, 18367, 18371, 18379, 18397, 18401, 18413, 18427, 18433, 18439, 18443, 18451, 18457, 18461, 18481, 18493, 18503, 18517, 18521, 18523, 18539, 18541, 18553, 18583, 18587, 18593, 18617, 18637, 18661, 18671, 18679, 18691, 18701, 18713, 18719, 18731, 18743, 18749, 18757, 18773, 18787, 18793, 18797, 18803, 18839, 18859, 18869, 18899, 18911, 18913, 18917, 18919, 18947, 18959, 18973, 18979, 19001, 19009, 19013, 19031, 19037, 19051, 19069, 19073, 19079, 19081, 19087, 19121, 19139, 19141, 19157, 19163, 19181, 19183, 19207, 19211, 19213, 19219, 19231, 19237, 19249, 19259, 19267, 19273, 19289, 19301, 19309, 19319, 19333, 19373, 19379, 19381, 19387, 19391, 19403, 19417, 19421, 19423, 19427, 19429, 19433, 19441, 19447, 19457, 19463, 19469, 19471, 19477, 19483, 19489, 19501, 19507, 19531, 19541, 19543, 19553, 19559, 19571, 19577, 19583, 19597, 19603, 19609, 19661, 19681, 19687, 19697, 19699, 19709, 19717, 19727, 19739, 19751, 19753, 19759, 19763, 19777, 19793, 19801, 19813, 19819, 19841, 19843, 19853, 19861, 19867, 19889, 19891, 19913, 19919, 19927, 19937, 19949, 19961, 19963, 19973, 19979, 19991, 19993, 19997, 20011, 20021, 20023, 20029, 20047, 20051, 20063, 20071, 20089, 20101, 20107, 20113, 20117, 20123, 20129, 20143, 20147, 20149, 20161, 20173, 20177, 20183, 20201, 20219, 20231, 20233, 20249, 20261, 20269, 20287, 20297, 20323, 20327, 20333, 20341, 20347, 20353, 20357, 20359, 20369, 20389, 20393, 20399, 20407, 20411, 20431, 20441, 20443, 20477, 20479, 20483, 20507, 20509, 20521, 20533, 20543, 20549, 20551, 20563, 20593, 20599, 20611, 20627, 20639, 20641, 20663, 20681, 20693, 20707, 20717, 20719, 20731, 20743, 20747, 20749, 20753, 20759, 20771, 20773, 20789, 20807, 20809, 20849, 20857, 20873, 20879, 20887, 20897, 20899, 20903, 20921, 20929, 20939, 20947, 20959, 20963, 20981, 20983, 21001, 21011, 21013, 21017, 21019, 21023, 21031, 21059, 21061, 21067, 21089, 21101, 21107, 21121, 21139, 21143, 21149, 21157, 21163, 21169, 21179, 21187, 21191, 21193, 21211, 21221, 21227, 21247, 21269, 21277, 21283, 21313, 21317, 21319, 21323, 21341, 21347, 21377, 21379, 21383, 21391, 21397, 21401, 21407, 21419, 21433, 21467, 21481, 21487, 21491, 21493, 21499, 21503, 21517, 21521, 21523, 21529, 21557, 21559, 21563, 21569, 21577, 21587, 21589, 21599, 21601, 21611, 21613, 21617, 21647, 21649, 21661, 21673, 21683, 21701, 21713, 21727, 21737, 21739, 21751, 21757, 21767, 21773, 21787, 21799, 21803, 21817, 21821, 21839, 21841, 21851, 21859, 21863, 21871, 21881, 21893, 21911, 21929, 21937, 21943, 21961, 21977, 21991, 21997, 22003, 22013, 22027, 22031, 22037, 22039, 22051, 22063, 22067, 22073, 22079, 22091, 22093, 22109, 22111, 22123, 22129, 22133, 22147, 22153, 22157, 22159, 22171, 22189, 22193, 22229, 22247, 22259, 22271, 22273, 22277, 22279, 22283, 22291, 22303, 22307, 22343, 22349, 22367, 22369, 22381, 22391, 22397, 22409, 22433, 22441, 22447, 22453, 22469, 22481, 22483, 22501, 22511, 22531, 22541, 22543, 22549, 22567, 22571, 22573, 22613, 22619, 22621, 22637, 22639, 22643, 22651, 22669, 22679, 22691, 22697, 22699, 22709, 22717, 22721, 22727, 22739, 22741, 22751, 22769, 22777, 22783, 22787, 22807, 22811, 22817, 22853, 22859, 22861, 22871, 22877, 22901, 22907, 22921, 22937, 22943, 22961, 22963, 22973, 22993, 23003, 23011, 23017, 23021, 23027, 23029, 23039, 23041, 23053, 23057, 23059, 23063, 23071, 23081, 23087, 23099, 23117, 23131, 23143, 23159, 23167, 23173, 23189, 23197, 23201, 23203, 23209, 23227, 23251, 23269, 23279, 23291, 23293, 23297, 23311, 23321, 23327, 23333, 23339, 23357, 23369, 23371, 23399, 23417, 23431, 23447, 23459, 23473, 23497, 23509, 23531, 23537, 23539, 23549, 23557, 23561, 23563, 23567, 23581, 23593, 23599, 23603, 23609, 23623, 23627, 23629, 23633, 23663, 23669, 23671, 23677, 23687, 23689, 23719, 23741, 23743, 23747, 23753, 23761, 23767, 23773, 23789, 23801, 23813, 23819, 23827, 23831, 23833, 23857, 23869, 23873, 23879, 23887, 23893, 23899, 23909, 23911, 23917, 23929, 23957, 23971, 23977, 23981, 23993, 24001, 24007, 24019, 24023, 24029, 24043, 24049, 24061, 24071, 24077, 24083, 24091, 24097, 24103, 24107, 24109, 24113, 24121, 24133, 24137, 24151, 24169, 24179, 24181, 24197, 24203, 24223, 24229, 24239, 24247, 24251, 24281, 24317, 24329, 24337, 24359, 24371, 24373, 24379, 24391, 24407, 24413, 24419, 24421, 24439, 24443, 24469, 24473, 24481, 24499, 24509, 24517, 24527, 24533, 24547, 24551, 24571, 24593, 24611, 24623, 24631, 24659, 24671, 24677, 24683, 24691, 24697, 24709, 24733, 24749, 24763, 24767, 24781, 24793, 24799, 24809, 24821, 24841, 24847, 24851, 24859, 24877, 24889, 24907, 24917, 24919, 24923, 24943, 24953, 24967, 24971, 24977, 24979, 24989, 25013, 25031, 25033, 25037, 25057, 25073, 25087, 25097, 25111, 25117, 25121, 25127, 25147, 25153, 25163, 25169, 25171, 25183, 25189, 25219, 25229, 25237, 25243, 25247, 25253, 25261, 25301, 25303, 25307, 25309, 25321, 25339, 25343, 25349, 25357, 25367, 25373, 25391, 25409, 25411, 25423, 25439, 25447, 25453, 25457, 25463, 25469, 25471, 25523, 25537, 25541, 25561, 25577, 25579, 25583, 25589, 25601, 25603, 25609, 25621, 25633, 25639, 25643, 25657, 25667, 25673, 25679, 25693, 25703, 25717, 25733, 25741, 25747, 25759, 25763, 25771, 25793, 25799, 25801, 25819, 25841, 25847, 25849, 25867, 25873, 25889, 25903, 25913, 25919, 25931, 25933, 25939, 25943, 25951, 25969, 25981, 25997, 25999, 26003, 26017, 26021, 26029, 26041, 26053, 26083, 26099, 26107, 26111, 26113, 26119, 26141, 26153, 26161, 26171, 26177, 26183, 26189, 26203, 26209, 26227, 26237, 26249, 26251, 26261, 26263, 26267, 26293, 26297, 26309, 26317, 26321, 26339, 26347, 26357, 26371, 26387, 26393, 26399, 26407, 26417, 26423, 26431, 26437, 26449, 26459, 26479, 26489, 26497, 26501, 26513, 26539, 26557, 26561, 26573, 26591, 26597, 26627, 26633, 26641, 26647, 26669, 26681, 26683, 26687, 26693, 26699, 26701, 26711, 26713, 26717, 26723, 26729, 26731, 26737, 26759, 26777, 26783, 26801, 26813, 26821, 26833, 26839, 26849, 26861, 26863, 26879, 26881, 26891, 26893, 26903, 26921, 26927, 26947, 26951, 26953, 26959, 26981, 26987, 26993, 27011, 27017, 27031, 27043, 27059, 27061, 27067, 27073, 27077, 27091, 27103, 27107, 27109, 27127, 27143, 27179, 27191, 27197, 27211, 27239, 27241, 27253, 27259, 27271, 27277, 27281, 27283, 27299, 27329, 27337, 27361, 27367, 27397, 27407, 27409, 27427, 27431, 27437, 27449, 27457, 27479, 27481, 27487, 27509, 27527, 27529, 27539, 27541, 27551, 27581, 27583, 27611, 27617, 27631, 27647, 27653, 27673, 27689, 27691, 27697, 27701, 27733, 27737, 27739, 27743, 27749, 27751, 27763, 27767, 27773, 27779, 27791, 27793, 27799, 27803, 27809, 27817, 27823, 27827, 27847, 27851, 27883, 27893, 27901, 27917, 27919, 27941, 27943, 27947, 27953, 27961, 27967, 27983, 27997, 28001, 28019, 28027, 28031, 28051, 28057, 28069, 28081, 28087, 28097, 28099, 28109, 28111, 28123, 28151, 28163, 28181, 28183, 28201, 28211, 28219, 28229, 28277, 28279, 28283, 28289, 28297, 28307, 28309, 28319, 28349, 28351, 28387, 28393, 28403, 28409, 28411, 28429, 28433, 28439, 28447, 28463, 28477, 28493, 28499, 28513, 28517, 28537, 28541, 28547, 28549, 28559, 28571, 28573, 28579, 28591, 28597, 28603, 28607, 28619, 28621, 28627, 28631, 28643, 28649, 28657, 28661, 28663, 28669, 28687, 28697, 28703, 28711, 28723, 28729, 28751, 28753, 28759, 28771, 28789, 28793, 28807, 28813, 28817, 28837, 28843, 28859, 28867, 28871, 28879, 28901, 28909, 28921, 28927, 28933, 28949, 28961, 28979, 29009, 29017, 29021, 29023, 29027, 29033, 29059, 29063, 29077, 29101, 29123, 29129, 29131, 29137, 29147, 29153, 29167, 29173, 29179, 29191, 29201, 29207, 29209, 29221, 29231, 29243, 29251, 29269, 29287, 29297, 29303, 29311, 29327, 29333, 29339, 29347, 29363, 29383, 29387, 29389, 29399, 29401, 29411, 29423, 29429, 29437, 29443, 29453, 29473, 29483, 29501, 29527, 29531, 29537, 29567, 29569, 29573, 29581, 29587, 29599, 29611, 29629, 29633, 29641, 29663, 29669, 29671, 29683, 29717, 29723, 29741, 29753, 29759, 29761, 29789, 29803, 29819, 29833, 29837, 29851, 29863, 29867, 29873, 29879, 29881, 29917, 29921, 29927, 29947, 29959, 29983, 29989, 30011, 30013, 30029, 30047, 30059, 30071, 30089, 30091, 30097, 30103, 30109, 30113, 30119, 30133, 30137, 30139, 30161, 30169, 30181, 30187, 30197, 30203, 30211, 30223, 30241, 30253, 30259, 30269, 30271, 30293, 30307, 30313, 30319, 30323, 30341, 30347, 30367, 30389, 30391, 30403, 30427, 30431, 30449, 30467, 30469, 30491, 30493, 30497, 30509, 30517, 30529, 30539, 30553, 30557, 30559, 30577, 30593, 30631, 30637, 30643, 30649, 30661, 30671, 30677, 30689, 30697, 30703, 30707, 30713, 30727, 30757, 30763, 30773, 30781, 30803, 30809, 30817, 30829, 30839, 30841, 30851, 30853, 30859, 30869, 30871, 30881, 30893, 30911, 30931, 30937, 30941, 30949, 30971, 30977, 30983, 31013, 31019, 31033, 31039, 31051, 31063, 31069, 31079, 31081, 31091, 31121, 31123, 31139, 31147, 31151, 31153, 31159, 31177, 31181, 31183, 31189, 31193, 31219, 31223, 31231, 31237, 31247, 31249, 31253, 31259, 31267, 31271, 31277, 31307, 31319, 31321, 31327, 31333, 31337, 31357, 31379, 31387, 31391, 31393, 31397, 31469, 31477, 31481, 31489, 31511, 31513, 31517, 31531, 31541, 31543, 31547, 31567, 31573, 31583, 31601, 31607]

def find_divider(x, edge=None):
	global primes
	if edge is None:
		edge = round(x ** (1 / 2))
	for prime in primes:
		if prime > edge:
			return x
		if x % prime == 0:
			return prime
	return x
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split(' ')]
	n = n + find_divider(n) + 2 * (k - 1)
	print(n)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	f = False
	c = 0
	for i in range(2, int(n ** (1 / 2)) + 1):
		if n % i == 0:
			f = True
			c = i
			break
	if not f:
		c = n
	if c == 2:
		print(n + c * k)
	else:
		print(n + c + 2 * (k - 1))


for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	res = 0
	if n % 2 == 0:
		res = n + 2 * k
		print(res)
	else:
		check = 3
		while True:
			if n % check == 0:
				break
			else:
				check += 2
		res = n + check + (k - 1) * 2
		print(res)


import math
for _ in range(int(input())):
	a = input().split(' ')
	n = int(a[0])
	k = int(a[1])
	while k > 0:
		value = 0
		val = int(math.sqrt(n)) + 1
		for i in range(2, val):
			if n % i == 0:
				value = i
				break
		if value == 0:
			value = n
		if value == 2:
			value = 2 * k
			k = 1
		n = value + n
		k = k - 1
	print(n)


def sd(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = int(input())
for z in range(t):
	(n, k) = [int(i) for i in input().split()]
	for i in range(k):
		r = sd(n)
		if r == 2:
			n += (k - i) * 2
			break
		n += r
	print(n)


t = int(input())
for x in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if n % 2 == 0:
		ans = 2 * k + n
		ans = int(ans)
		print(ans)
	else:
		for a in range(2, n + 1):
			if n % a == 0:
				break
		ans = 2 * (k - 1) + n + a
		ans = int(ans)
		print(ans)


t = int(input())
for _ in range(t):
	(n0, n1) = map(int, input().split())
	p = 0
	for i in range(2, n0 + 1):
		if n0 % i == 0:
			p = i
			break
	print(p + (n1 - 1) * 2 + n0)


import sys, bisect
from math import gcd
input = sys.stdin.readline

def inp():
	return int(input().rstrip())

def inlt():
	return list(map(int, input().rstrip().split()))

def insr():
	s = input().rstrip()
	return s[:len(s) - 1]

def invr():
	return map(int, input().rstrip().split())

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = inp()
for _ in range(t):
	(n, k) = invr()
	small = smallestDivisor(n)
	while small != 2:
		n += small
		small = smallestDivisor(n)
		k -= 1
		if k < 1:
			break
	n += k * 2
	print(n)


def main():
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		ans = n + 2 * k
		print(ans)
		return
	else:
		for i in range(3, n + 1):
			if n % i == 0:
				ans = n + 2 * (k - 1) + i
				print(ans)
				return
t = int(input())
while t:
	main()
	t -= 1


import sys
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
sys.setrecursionlimit(10 ** 7)
mod = 1000000007

def IOE():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def main():
	t = int(sys.stdin.readline())
	for _ in range(t):
		(n, k) = map(int, sys.stdin.readline().split())
		if n % 2 == 0:
			print(n + k * 2)
		elif isPrime(n):
			ans = n * 2 + (k - 1) * 2
			print(ans)
		else:
			fi = 0
			for i in range(2, n):
				if n % i == 0:
					fi = i
					break
			n = n + fi + (k - 1) * 2
			print(n)
try:
	IOE()
except:
	pass
main()


import math

def f(n):
	a = int(math.sqrt(n))
	for i in range(2, a + 1):
		if n % i == 0:
			return i
	return n

def ans(n, k):
	if n % 2 == 0:
		return n + 2 * k
	else:
		z = f(n)
		n += z
		return n + 2 * (k - 1)
k = int(input())
for i in range(k):
	a = input().split()
	n = int(a[0])
	m = int(a[1])
	print(ans(n, m))


def f(x):
	for i in range(2, int(x ** 0.5) + 2):
		if x % i == 0:
			return i
	return x
t = int(input())
for q in range(t):
	(n, k) = map(int, input().split())
	for i in range(k):
		a = f(n)
		b = n // a
		if a == 2:
			n += k * a
			break
		n += a
		k -= 1
	print(n)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		n = n + 2 * k
	else:
		i = 3
		while i <= int(math.sqrt(n)) and n % i != 0:
			i += 2
		if i > int(math.sqrt(n)):
			n = 2 * n
		else:
			n = n + i
		n = n + 2 * (k - 1)
	print(n)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split(' '))
	d = n
	ck = k
	for j in range(k):
		if d > 2:
			for l in range(2, n):
				if n % l == 0:
					d = l
					break
			n = n + d
		else:
			ck = j
			break
	n = n + 2 * (k - ck)
	print(n)


t = int(input())

def first_div(no):
	for i in range(2, no // 2 + 1):
		if no % i == 0:
			return i
	return no
for _ in range(t):
	(n, k) = map(int, input().split())
	lolark = 0
	lolark = n + first_div(n)
	lolark += 2 * (k - 1)
	print(lolark)


def seive():
	maxN = 10 ** 6
	arr = [-1] * (maxN + 1)
	for i in range(2, maxN + 1):
		if arr[i] == -1:
			for j in range(i, maxN + 1, i):
				if arr[j] == -1:
					arr[j] = i
	return arr
x = seive()
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	sum = 0
	sum += n + x[n] + 2 * (k - 1)
	print(sum)


t = int(input())
respostas = []

def menor_divisor(n):
	for _ in range(2, n + 1):
		if n % _ == 0:
			return _
			break
for x in range(t):
	(n, k) = map(int, input().split())
	while k > 0:
		if n % 2 == 0:
			n += 2 * k
			break
		else:
			f = menor_divisor(n)
			n += f
		k -= 1
	respostas.append(n)
for x in respostas:
	print(x)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n % 2:
		m -= 1
		d = 3
		while d * d <= n and n % d:
			d += 1
		if d * d > n:
			d = n
		n += d
	n += 2 * m
	print(n)


import math
n = int(input())
for i in range(n):
	flag = 0
	s = 0
	(a, b) = map(int, input().split())
	for k in range(2, int(math.sqrt(a)) + 1):
		if a % k == 0:
			s = s + k + a
			break
	else:
		s = s + a + a
	b = b - 1
	print(s + b * 2)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n
	for i in range(1):
		flag = 0
		for j in range(2, int(math.sqrt(ans) + 1)):
			if ans % j == 0:
				ans += j
				flag = 1
				break
		if flag == 0:
			ans = 2 * ans
	ans = ans + 2 * (k - 1)
	print(ans)


def f(n):
	if n % 2 == 0:
		return 2
	else:
		for i in range(3, int(n ** 0.5) + 1, 2):
			if n % i == 0:
				break
		else:
			i = n
	return i
for _ in [0] * int(input()):
	(a, b) = map(int, input().split())
	print(f(a) + a + 2 * (b - 1))


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	for i in range(2, N + 1):
		if N % i == 0:
			Number = i
			break
	while Number != 2 and K > 0:
		N += Number
		K -= 1
		for i in range(2, N + 1):
			if N % i == 0:
				Number = i
				break
	print(N + K * Number)


def solve():
	(n, k) = [int(x) for x in input().split()]
	for i in range(2, n + 1):
		if n % i == 0:
			d = i
			break
	print(n + d + (k - 1) * 2)
T = int(input())
for _ in range(T):
	solve()


t = int(input())

def get_lcf(n):
	i = 3
	while True:
		if n % i == 0:
			return i
		i += 2
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	ans = n
	flag = 1
	if ans % 2 == 0:
		print(ans + 2 * k)
		continue
	for i in range(k):
		if ans % 2 == 0:
			print(ans + 2 * (k - i))
			flag = 0
			break
		ans = get_lcf(ans) + ans
	if flag:
		print(ans)


for f in range(int(input())):
	(n, k) = map(int, input().split())
	div = 2
	while div * div < n and n % div != 0:
		div += 1
	if div * div > n:
		div = n
	print(n + div + (k - 1) * 2)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	total = n
	if n % 2 == 0:
		print(n + 2 * k)
		continue
	fac = 0
	for j in range(total, 1, -1):
		if total % j == 0:
			fac = j
	print(n + fac + 2 * (k - 1))


import math
t = int(input())
for i in range(t):
	num = list(map(int, input().split()))
	n = num[0]
	k = num[1]
	m = int(math.sqrt(n))
	if n % 2 == 1:
		ck = 0
		for j in range(2, m + 1):
			if n % j == 0:
				n = n + j
				ck = 1
				break
		if ck == 0:
			n = n + n
		print(n + (k - 1) * 2)
	else:
		print(n + k * 2)


def SD(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		for j in range(k):
			if n % 2 != 0:
				n = n + SD(n)
			else:
				n = n + (k - j) * 2
				print(n)
				break
		else:
			print(n)


import math
from collections import defaultdict, Counter, deque

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	(n, k) = map(int, input().split())
	while k > 0 and n % 2 != 0:
		n += primeFactor(n)
		k -= 1
	n += 2 * k
	print(n)
	return
t = int(input())
for _ in range(t):
	main()


cases = int(input())

def isprime(n):
	for i in range(2, n // 2 + 1):
		if n % i == 0:
			return i
	return -1
for j in range(cases):
	l = list(map(int, input().rstrip().split()))
	x = isprime(l[0])
	if x != -1:
		print(l[0] + x + (l[1] - 1) * 2)
	else:
		print(l[0] + l[0] + (l[1] - 1) * 2)


import math
a = int(input())

def smallestFactor(k):
	for i in range(2, k + 1):
		if k % i == 0:
			return i
for i in range(0, a):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		print(n + smallestFactor(n) + (k - 1) * 2)


def smallestDiv(n):
	rootN = pow(n, 0.5)
	for i in range(3, int(rootN) + 1):
		if n % i == 0:
			return i
		i += 2
	return n
t = int(input())
for i in range(t):
	NK = list(map(int, input().split()))
	n = NK[0]
	k = NK[1]
	if n % 2 == 0:
		n += k * 2
		print(n)
	else:
		n += smallestDiv(n) + (k - 1) * 2
		print(n)


from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = int(input())
for c in range(t):
	(n, k) = [int(x) for x in input().split()]
	if n % 2 == 1:
		k -= 1
		factorss = list(factors(n))
		factorss.sort()
		n += factorss[1]
	n += 2 * k
	print(n)


t = int(input())
arr = []
for _ in range(t):
	(n, k) = map(int, input().split())
	p = False
	x = -1
	for i in range(2, n):
		if n % i == 0:
			x = i
			p = True
			break
	if p == False:
		curr = 2 * n
		print(curr + 2 * (k - 1))
	else:
		curr = n + x
		print(curr + 2 * (k - 1))


from sys import stdin, stdout
q = int(input())

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for i in range(q):
	(n, k) = list(map(int, stdin.readline().split()))
	d = smallestDivisor(n)
	if n % 2 == 0:
		print(n + d * k)
	else:
		e = n + d
		print(e + 2 * (k - 1))


def get_smallest_divisor(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	for i in range(k):
		t = get_smallest_divisor(n)
		if t == 2:
			n += 2 * (k - i)
			break
		n += t
	print(n)


def factors(n):
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def add_to_n(n, k):
	if n % 2 == 0 and k > 0:
		return n + k * 2
	else:
		for i in range(k):
			if n % 2 == 0:
				return n + (k - i) * 2
			n += factors(n)
		return n
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(add_to_n(n, k))


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, Counter
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = intIn()
while t > 0:
	t -= 1
	(n, k) = listIn()
	s = smallestDivisor(n)
	ans = n + s + 2 * (k - 1)
	print(ans)


for _ in range(int(input())):
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	r = 0

	def ge(a: int):
		for i in range(2, int(a // 2) + 1):
			if a % i == 0:
				return i
		return a
	j = 1
	while j < 2:
		r = ge(n) + n
		n = r
		j += 1
	n += 2 * (m - 1)
	print(n)


t = int(input())

def minFactor(num):
	if num % 3 == 0:
		return 3
	else:
		for h in range(5, num + 1, 6):
			if num % h == 0:
				return h
			if num % (h + 2) == 0:
				return h + 2
for i in range(t):
	line = input().split()
	n = int(line[0])
	k = int(line[1])
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		f = n + minFactor(n)
		print(f + 2 * (k - 1))


s = []
for jjj in range(int(input())):
	(n, k) = map(int, input().split())
	p = n
	while p != 2 and k != 0:
		for i in range(2, n + 1):
			if n % i == 0:
				p = i
				n += p
				k -= 1
				break
	n += k * 2
	s.append(n)
for i in s:
	print(i)


def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		i = 2
		ans = n
		while i * i <= n:
			if n % i == 0:
				ans = i
				break
			i += 1
		if ans % 2 == 1:
			print(n + ans + 2 * (k - 1))
		else:
			print(n + 2 * k)
main()


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	for t in range(I()):
		(n, k) = In()
		flag = 1
		for j in range(2, int(math.sqrt(n)) + 1):
			if n % j == 0:
				n += j
				flag = 0
				break
		if flag:
			n *= 2
		print(n + 2 * (k - 1))
main()


import math
t = int(input())
for z in range(t):
	f = 0
	(n, k) = map(int, input().split())
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			f = 1
			break
	if f == 1:
		n = i + n
	else:
		n = n + n
	if k == 1:
		print(n)
		continue
	n = n + 2 * (k - 1)
	print(n)


def sd(n):
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for i in range(int(input())):
	(a, b, c, d, l, s) = (0, 0, 0, 0, [], [])
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + k * 2)
	else:
		while True:
			if n % 2 == 0:
				n = n + (k - b) * 2
				break
			else:
				b = b + 1
				r = sd(n)
				n = n + r
				if b == k:
					break
		print(n)


t = int(input())
for j in range(t):
	(n, m) = map(int, input().split())
	for i in range(2, n + 1):
		if n % i == 0:
			break
	ans = n + i
	m = m - 1
	ans += 2 * m
	print(ans)


def r(t=int):
	return list(map(t, input().split()))

def ri(t=int):
	return t(input())

def cd(it):
	ret_val = dict()
	for v in it:
		ret_val[v] = ret_val.get(v, 0) + 1
	return ret_val

def min_div(n):
	for i in range(2, n + 1):
		if not n % i:
			return i
for _ in range(ri()):
	(n, k) = r()
	ans = min_div(n) + n
	ans += (k - 1) * 2
	print(ans)


def f(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return i
	return n
rw = int(input())
for ewqr in range(rw):
	(n, k) = map(int, input().split())
	t = f(n)
	print(n + t + 2 * (k - 1))


from math import sqrt

def check(n):
	for x in range(2, int(sqrt(n)) + 1):
		if n % x == 0:
			return x
	return n
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	j = 0
	for x in range(b):
		t = check(a)
		a = a + t
		j = x
		if t == 2:
			break
	if j != b - 1:
		a = a + 2 * (b - 1 - j)
	print(a)


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	if not n % 2:
		print(n + k * 2)
	else:
		x = n
		for i in range(3, int(n ** 0.5) + 1, 2):
			if not n % i:
				x = i
				break
		print(n + (k - 1) * 2 + x)


def smallestdiv(n):
	N = n
	i = 2
	while i * i <= n:
		if n % i == 0:
			return i
		i += 1
	return N
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	n1 = smallestdiv(n)
	if n1 == n:
		print(n1 * 2 + (k - 1) * 2)
	else:
		print(n + n1 + (k - 1) * 2)


import math

def sp(n):
	l = [0] * (10 ** 6 + 5)
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			l[p] = 1
	return l
li = sp(10 ** 6 + 5)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	elif li[n]:
		print(2 * n + 2 * (k - 1))
	else:
		t = 1
		for i in range(len(li)):
			if li[i]:
				if n % i == 0:
					t = i
					break
		print(n + t + 2 * (k - 1))


t = int(input())
temp = 0
while t > 0:
	(n, k) = list(map(int, input().split()))
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		for i in range(2, n + 1):
			if n % i == 0:
				temp = i
				break
		print(n + i + 2 * (k - 1))
	t -= 1


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	r = n
	for i in range(2, int(math.sqrt(n) + 1)):
		if n % i == 0:
			n = n + i
			break
		else:
			continue
	if n == r:
		n += n
	else:
		pass
	n = n + 2 * (k - 1)
	print(n)


import sys, math
from collections import defaultdict as dd
input = sys.stdin.readline
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		x = n
		for i in range(3, n + 1):
			if n % i == 0:
				x = i
				break
		n = n + x
		if k != 1:
			print(n + 2 * (k - 1))
		else:
			print(n)


import math
t = int(input())
while t:
	(n, k) = map(int, input().split())
	req = n
	val = 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			req = i
			break
	if req == n:
		val = n * 2 + 2 * (k - 1)
	else:
		val = n + req * 1 + 2 * (k - 1)
	print(val)
	t = t - 1


for i in range(int(input())):
	(a, b) = map(int, input().split())
	s = 0
	for k in range(2, a + 1):
		if a % k == 0:
			s = k
			break
	print(a + s + 2 * (b - 1))


no = int(input())
div = 0
res = []
for i in range(no):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		res.append(int(n + 2 * k))
	else:
		for i in range(2, n + 1):
			if n % i == 0:
				div = i
				break
		res.append(n + div + 2 * (k - 1))
for i in res:
	print(i)


t = int(input())

def min_v(a):
	for i in range(2, a + 1):
		if a % i == 0:
			return i
for q in range(t):
	(n, k) = map(int, input().split())
	res = 0
	n += min_v(n)
	n += 2 * (k - 1)
	print(n)


from sys import stdin, stdout
import math
from collections import defaultdict
input = stdin.buffer.readline

def meth(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i

def isprime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	if isprime(n):
		print(2 * n + 2 * (k - 1))
	else:
		print(n + meth(n) + 2 * (k - 1))


from math import sqrt
from math import floor

def small_div(n):
	if n % 2 == 0:
		return 2
	for i in range(3, n + 1):
		if n % i == 0:
			return i
t = int(input())
while t > 0:
	(n, k) = [int(x) for x in input().split()]
	n += small_div(n)
	k -= 1
	n += 2 * k
	print(n)
	t -= 1


import math

def get(k):
	for i in range(2, int(math.sqrt(k)) + 1):
		if k % i == 0:
			return i
	return k
n = int(input())
for emergence in range(n):
	(a, b) = map(int, input().split())
	if a % 2 == 0:
		print(a + b * 2)
	else:
		print(a + get(a) + (b - 1) * 2)


def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def div(n):
	a = 0
	if isPrime(n):
		return n
	else:
		for i in range(2, n // 2 + 1):
			if n % i == 0:
				return i
for i in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 0
	if isPrime(n):
		print(2 * n + 2 * (k - 1))
	elif n % 2 == 0:
		print(n + 2 * k)
	else:
		print(n + div(n) + 2 * (k - 1))


import math

def ri():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def inp():
	return int(input())

def si():
	return input()

def pYes():
	print('YES')

def pNo():
	print('NO')

def plist(l):
	print(''.join(l))
t = int(input())
for t1 in range(t):
	(a, b) = ri()
	if a % 2 == 0:
		a += 2 * b
		print(a)
	else:
		for i in range(2, a + 1):
			if a % i == 0:
				break
		print(a + i + (b - 1) * 2)


from math import sqrt

def smallest_prime(number):
	for i in range(2, int(sqrt(number) + 2)):
		if number % i == 0:
			return i
	return number

def find_n(n, k):
	return n + smallest_prime(n) + (k - 1) * 2
count = int(input())
input_l = []
for i in range(count):
	(n, k) = input().split()
	input_l.append([int(n), int(k)])
for i in input_l:
	print(find_n(*i))


def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
			break
		i += 2
	return n
for i in range(int(input())):
	(a, b) = map(int, input().split())
	c = smallestDivisor(a)
	d = c + a
	print(d + 2 * (b - 1))


from collections import deque, defaultdict
import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * m)
	else:
		ans = 0
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				ans = i
				break
		if ans == 0:
			ans = n
		print(ans + n + (m - 1) * 2)


t = int(input())

def f(n):
	if not n % 2:
		return 2
	if not n % 3:
		return 3
	i = 5
	while i * i <= n:
		if n % i == 0:
			return i
		if n % (i + 2) == 0:
			return i + 2
		i = i + 6
	return n
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	for i in range(k):
		if not n % 2:
			n += (k - i) * 2
			break
		n += f(n)
	print(n)


from sys import stdin
import math
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = 0
	for x in range(2, int(math.sqrt(n)) + 1):
		if n % x == 0:
			a = x
			break
	if a == 0:
		a = n
	if a > 2:
		print(n + a + 2 * (k - 1))
	else:
		print(n + a * k)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	num = 0
	for i in range(k):
		num1 = num
		num = 0
		for j in range(2, int(n ** 0.5) + 2):
			if n % j == 0:
				num = j
				break
		if num == 0:
			num = n
		if num == num1:
			n += num * (k - i)
			break
		n += num
	print(n)


import math
t = int(input())
for j in range(t):
	g = list(map(int, input().split()))
	n = g[0]
	k = g[1]
	c = n
	d = 0
	if n % 2 == 0:
		c += 2 * k
	else:
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0:
				c += i
				d = 1
				break
		if d == 0:
			c += n
		c += 2 * (k - 1)
	print(c)


def menor_divisor(number):
	if number % 2 == 0:
		return 2
	i = 3
	while i * i <= number:
		if number % i == 0:
			return i
		i += 2
	return number
for _ in range(int(input())):
	(number, k) = [int(x) for x in input().split()]
	if number % 2 == 0:
		print(number + k * 2)
		continue
	else:
		for i in range(k):
			if menor_divisor(number) == 2:
				number = number + (k - i) * 2
				break
			else:
				number += menor_divisor(number)
		print(number)


import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from heapq import heappush, heappop, heapify, nlargest, nsmallest

def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def sortListWithIndex(listOfTuples, idx):
	return sorted(listOfTuples, key=lambda x: x[idx])

def sortDictWithVal(passedDic):
	temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
	toret = {}
	for tup in temp:
		toret[tup[0]] = tup[1]
	return toret

def sortDictWithKey(passedDic):
	return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
t = INT()
while t != 0:
	(n, k) = MAP()
	if n % 2 == 0:
		ans = n + 2 * k
	else:
		for i in range(2, n + 1):
			if n % i == 0:
				break
		ans = n + i + 2 * (k - 1)
	print(ans)
	t -= 1


from sys import stdin, stdout

def f(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	if n % 2 == 0:
		n += 2 * k
	else:
		for i in range(k):
			n += f(n)
			if n % 2 == 0:
				n += 2 * (k - i - 1)
				break
	stdout.write(str(n) + '\n')


n = int(input())
for i in range(n):
	(a, b) = [int(i) for i in input().split(' ')]
	if a % 2 == 0:
		result = a + b * 2
	else:
		result = a + (b - 1) * 2
		j = 3
		while a % j != 0:
			j += 2
		result += j
	print(result)


for i in range(0, int(input())):
	(n, k) = map(int, input().split())
	numero = n
	minimo = 1
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			minimo = i
			numero += i
			break
	if minimo == 1:
		numero += numero
		minimo = numero
		print(numero + 2 * (k - 1))
	else:
		print(numero + 2 * (k - 1))


m = 1000000
leastPrimefactor = [0] * (m + 1)
leastPrimefactor[1] = 1
for i in range(2, m + 1):
	if leastPrimefactor[i] == 0:
		leastPrimefactor[i] = i
		for j in range(i, m + 1, i):
			if leastPrimefactor[j] == 0:
				leastPrimefactor[j] = i
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().rstrip().split())
	div = leastPrimefactor[n]
	n += div
	if k == 1:
		print(n)
		continue
	n += 2 * (k - 1)
	print(n)


from math import gcd, ceil
from collections import defaultdict as dd

def lcm(a, b):
	return a * b // gcd(a, b)

def inin():
	return int(input())

def inar():
	return list(map(int, input().split()))

def ar(element, size):
	return [element for i in range(size)]

def digitsum(num):
	su = 0
	while num:
		su += num % 10
		num //= 10
	return su

def pred(n, k, pointer):
	return pointer - k >= n

def yes():
	print('YES')

def no():
	print('NO')
Testcase = inin()
for _ in range(Testcase):
	(n, k) = inar()
	ld = n
	i = 2
	while i * i <= n:
		if n % i == 0:
			ld = i
			break
		i += 1
	print(n + ld + (k - 1) * 2)


import math
t = int(input())
for i in range(0, t):
	(n, k) = map(int, input().split())
	for j in range(1, n + 1):
		p = math.gcd(n, j)
		if p > 1:
			print(n + p + (k - 1) * 2)
			break


import sys
input = sys.stdin.readline
isPrime = [False, False] + [True for _ in range(999999)]
for i in range(2, int(1000000 ** 0.5) + 1):
	if isPrime[i]:
		for j in range(i * 2, 1000001, i):
			isPrime[j] = False
prime = [v for v in range(1000001) if isPrime[v]]
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	for num in prime:
		if n % num == 0:
			n += num
			n += (k - 1) * 2
			break
	print(n)


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	flag = 0
	x = 0
	for i in range(2, int(sqrt(n)) + 2):
		if n % i == 0:
			flag = 1
			x = i
			break
	if flag == 0:
		print(n + n + (k - 1) * 2)
	else:
		print(n + x + 2 * (k - 1))


from sys import stdin, stdout, setrecursionlimit
from math import sqrt, ceil

def print(n):
	stdout.write(str(n) + '\n')

def m(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
	return n
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	x = m(n)
	if x % 2 == 1:
		n += x
		n += 2 * (k - 1)
	else:
		n += k * x
	print(n)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	s = 0
	for i in range(2, n + 1):
		if n % i == 0:
			s = i
			break
	print(n + s + 2 * (m - 1))


t = int(input())
for i in range(t):
	l = [int(k) for k in input().split()]
	n = l[0]
	k = l[1]
	m = 2
	while m * m <= n:
		if n % m == 0:
			check = m
			break
		m += 1
	else:
		check = n
	n += check
	if k == 1:
		print(n)
	if k != 1:
		n = 2 * (k - 1) + n
		print(n)


from sys import stdin, stdout
import math

def fin_it(n):
	ans = -1
	for i in range(2, int(math.sqrt(n)) + 1):
		if not n % i:
			ans = i
			break
	if ans == -1:
		return n
	return ans
test = int(stdin.readline())
for _ in range(test):
	(N, K) = map(int, stdin.readline().split())
	fin_ans = N
	if N & 1 ^ 1:
		fin_ans += K * 2
	else:
		temp = fin_it(N)
		fin_ans += temp + 2 * (K - 1)
	print(fin_ans)


def small_divisor(num):
	limit = round(num ** 0.5) + 1
	for i in range(2, limit):
		if num % i == 0:
			return i
			break
	else:
		return num
for test_case in range(int(input())):
	(num, k) = map(int, input().split()[:2])
	num += small_divisor(num)
	addition = (k - 1) * 2
	num += addition
	print(num)


import math
t = int(input(''))
for test in range(t):
	inp = input('')
	(n, k) = [int(i) for i in inp.split()]
	if n % 2 == 0:
		n += k * 2
	else:
		f_n = 0
		for i in range(3, int(math.sqrt(n) + 1)):
			if n % i == 0:
				f_n = i
				n += i
				break
		if f_n == 0:
			n += n
		if k > 1:
			n += 2 * (k - 1)
	print(n)


def min_del(x):
	for i in range(2, x + 1):
		if x % i == 0:
			return i
n = int(input())
for _ in range(n):
	string = input().split()
	n = int(string[0])
	k = int(string[1])
	print(n + min_del(n) + 2 * (k - 1))


T = int(input())

def get_d(n):
	for i in range(3, int(pow(n, 0.5)) + 1):
		if n % i == 0:
			return i
	return n

def solve(n, k):
	if n % 2 == 1:
		d = get_d(n)
		ans = n + d + (k - 1) * 2
	else:
		ans = n + k * 2
	return ans
while T > 0:
	(n, k) = [int(el) for el in input().split(' ')]
	ans = solve(n, k)
	print(ans)
	T -= 1


tstr = input()
t = int(tstr)
nums = list()
for i in range(t):
	tstr = input().split()
	nums.append(int(tstr[0]))
	nums.append(int(tstr[1]))
	for j in range(nums[i * 2 + 1]):
		k = 2
		while nums[2 * i] % k != 0:
			k = k + 1
		if k == 2:
			nums[2 * i] = nums[2 * i] + 2 * (nums[i * 2 + 1] - j)
			break
		else:
			nums[2 * i] = nums[2 * i] + k
for i in range(t):
	print(nums[i * 2])


counter = int(input())
for c in range(counter):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
		continue
	else:
		prime = True
		for j in range(3, int(n / 2) + 1, 2):
			if n % j == 0:
				n = n + j
				prime = False
				break
		if prime:
			print(2 * n + 2 * (k - 1))
		else:
			print(n + 2 * (k - 1))


for _ in range(int(input())):
	l = list(input().split(' '))
	n = int(l[0])
	if n % 2 == 0:
		n = n + 2 * int(l[1])
	else:
		for j in range(3, n + 1, 2):
			if n % j == 0:
				n = n + j
				break
		n = n + 2 * (int(l[1]) - 1)
	print(n)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
prime = set()

def sieveEras(n):
	global prime
	m = n + 1
	numbers = [True] * m
	for i in range(2, int(n ** 0.5 + 1)):
		if numbers[i]:
			for j in range(i * i, m, i):
				numbers[j] = False
	for i in range(2, m):
		if numbers[i]:
			prime.add(i)
sieveEras(1000001)

def primeFactors(n):
	d = set()
	while n % 2 == 0:
		d.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			d.add(i)
			n = n // i
	if n > 2:
		d.add(n)
	return d
tc = ii1()
for _ in range(tc):
	(n, k) = iia()
	if n % 2 == 0:
		n += k * 2
	else:
		if n in prime:
			n *= 2
			k -= 1
		else:
			n += min(primeFactors(n))
			k -= 1
		if k > 0:
			n += k * 2
	print(n)


from sys import stdin
import math
for _ in range(int(stdin.readline())):
	(n, k) = list(map(int, stdin.readline().split()))
	sd = n
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			sd = i
			break
	n += sd
	k -= 1
	n += 2 * k
	print(n)


def small(x):
	for i in range(2, x + 1):
		if i == x ** (1 / 2) + 1:
			return x
			break
		elif x // i == float(x / i):
			return i
			break
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	p = k
	for j in range(k):
		if small(n) == 2:
			p = j
			break
		n += small(n)
	n += 2 * (k - p)
	print(n)


from sys import stdin

def solve(n, k):
	h = n
	i = 2
	while i * i <= h:
		if h % i == 0:
			break
		i += 1
	if h % i != 0:
		i = n
	ans = n + i
	if k >= 2:
		ans = ans + 2 * (k - 1)
	print(ans)
	return

def main():
	inp = stdin.readline
	for _ in range(int(inp())):
		(n, k) = map(int, inp().split())
		solve(n, k)
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		j = 3
		while True:
			if n % j == 0:
				break
			else:
				j += 2
		print(n + j + (k - 1) * 2)


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
from collections import *
for _ in range(ii()):
	(n, k) = f()
	if n % 2 == 0:
		print(n + 2 * k)
	else:
		while n % 2 != 0 and k >= 1:
			l = 0
			for i in range(3, n + 1):
				if n % i == 0:
					l = i
					break
			if k >= 1:
				n = n + l
				k = k - 1
		if n % 2 == 0:
			print(n + 2 * k)
		else:
			print(n)


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
entries = inp()
for i in range(entries):
	l = inlt()
	n = l[0]
	k = l[1]
	for j in range(k):
		m = 2
		if n % 2 == 0:
			n = n + 2 * (k - j)
			break
		while True:
			if n % m == 0:
				n += m
				break
			m += 1
	print(n)


def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = int(input())
for x in range(t):
	arr = list(map(int, input().split()))
	print((arr[0] % 2 == 0) * (arr[0] + 2 * arr[1]) + (arr[0] % 2 == 1) * (arr[0] + 2 * (arr[1] - 1) + smallestDivisor(arr[0])))


def f(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
for ad in range(int(input())):
	(n, k) = list(map(int, input().split()))
	c = f(n) + n
	c += 2 * (k - 1)
	print(c)


i = int(input())
for x in range(0, i):
	tab = input().split(sep=' ')
	n = int(tab[0])
	k = int(tab[1])
	for p in range(2, n + 1):
		f = False
		if n % p == 0:
			n = n + p
			f = True
		if f:
			break
	n += 2 * (k - 1)
	print(n)


from math import *
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	d = n
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			d = i
			break
	print(n + d + (k - 1) * 2)


import math
t = int(input())

def find(n):
	d = n
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			d = i
			break
	return d

def solve():
	(n, k) = map(int, input().split())
	total = n
	d = find(n)
	print(n + d + (k - 1) * 2)
for i in range(t):
	solve()


for _ in range(int(input())):
	X = list(map(int, input().split()))
	Min = 0
	for i in range(2, X[0] + 1):
		if X[0] % i == 0:
			Min = i
			break
	print(Min + X[0] + 2 * (X[1] - 1))


import math as mt
MAXN = 1000001
spf = [0 for i in range(MAXN)]

def sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, mt.ceil(mt.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
sieve()
t = int(input())
while t > 0:
	(n, k) = [int(n) for n in input().split()]
	suma = n + spf[n]
	suma = suma + (k - 1) * 2
	print(suma)
	t -= 1


n = int(input())
t = True
while n > 0:
	(a, b) = map(int, input().split())
	for j in range(2, a + 1):
		if a % j == 0:
			break
	a += j
	b -= 1
	a += b * 2
	print(a)
	n -= 1


def read_int():
	n = int(input())
	return n

def read_ints():
	ints = [int(x) for x in input().split(' ')]
	return ints

def smallest_divisor(n):
	for i in range(2, n // 2 + 1):
		if n % i == 0:
			return i
	return n

def solve(n, k):
	fn = n
	for i in range(k):
		if fn % 2 == 0:
			mult = k - i
			fn += 2 * mult
			return fn
		else:
			sd = smallest_divisor(fn)
			fn += sd
	return fn
t = read_int()
for case in range(t):
	(n, k) = read_ints()
	sol = solve(n, k)
	print(sol)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a % 2 == 0:
		print(a + 2 * b)
	else:
		r = 0
		for j in range(3, int(pow(a, 0.5)) + 1):
			if a % j == 0:
				r = 1
				break
		if r == 1:
			print(a + j + 2 * (b - 1))
		else:
			print(2 * a + 2 * (b - 1))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	z = 0
	if n % 2 == 0:
		w = n + 2 * k
		print(w)
	else:
		for i in range(2, abs(n) + 1):
			if n % i == 0:
				z = i
				break
		d = n + z + 2 * (k - 1)
		print(d)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n % 2 == 0:
		print(n + 2 * k)
		continue
	x = 0
	for i in range(n, 1, -1):
		if n % i == 0:
			x = i
	print(n + x + 2 * (k - 1))