The problem is quite simple. You're  given a number N and a positive integer K. Tell if N can be represented as a sum of K prime numbers (not necessarily distinct).

Input Format 

The first line contains a single integer T, denoting the number of test cases. 

Each of the next T lines contains two positive integers, N & K, separated by a single space.  

Output Format 

For every test case, output "Yes" or "No" (without quotes).

Constraints 

1 <= T <= 5000 

1 <= N <= 10^{12} 

1 <= K <= 10^{12}    

Sample Input

2
10 2
1 6

Sample Output

Yes
No

Explanation  

In the first case, 10 can be written as 5 + 5, and 5 is a prime number.
In the second case, 1 cannot be represented as a sum of prime numbers, because there are no prime numbers less than 1.

Difficulty: MEDIUM

Solutions:
import random
import sys

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	if n & 1 == 0:
		return False
	(s, d) = (0, n - 1)
	while d & 1 == 0:
		(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True

def f(n, k):
	if n < 2 * k:
		return False
	if k == 1:
		return is_probable_prime(n)
	if k == 2:
		if n % 2 == 0:
			return True
		else:
			return is_probable_prime(n - 2)
	return True
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print('Yes' if f(n, k) else 'No')


import math, random, sys

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	elif n & 1 == 0:
		return False
	else:
		(s, d) = (0, n - 1)
		while d & 1 == 0:
			(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True
T = int(sys.stdin.readline())
for _ in range(T):
	(N, K) = list(map(int, sys.stdin.readline().split()))
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes' if is_probable_prime(N) else 'No')
	elif K == 2:
		if N % 2 == 0:
			print('Yes')
		else:
			print('Yes' if is_probable_prime(N - 2) else 'No')
	else:
		print('Yes')


import math, random, sys

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	elif n & 1 == 0:
		return False
	else:
		(s, d) = (0, n - 1)
		while d & 1 == 0:
			(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True
T = int(sys.stdin.readline())
for _ in range(T):
	(N, K) = list(map(int, sys.stdin.readline().split()))
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes' if is_probable_prime(N) else 'No')
	elif K == 2:
		if N % 2 == 0:
			print('Yes')
		else:
			print('Yes' if is_probable_prime(N - 2) else 'No')
	else:
		print('Yes')


import math, random, sys

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	elif n & 1 == 0:
		return False
	else:
		(s, d) = (0, n - 1)
		while d & 1 == 0:
			(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True
T = int(sys.stdin.readline())
for _ in range(T):
	(N, K) = list(map(int, sys.stdin.readline().split()))
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes' if is_probable_prime(N) else 'No')
	elif K == 2:
		if N % 2 == 0:
			print('Yes')
		else:
			print('Yes' if is_probable_prime(N - 2) else 'No')
	else:
		print('Yes')


import math, random, sys

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	elif n & 1 == 0:
		return False
	else:
		(s, d) = (0, n - 1)
		while d & 1 == 0:
			(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True
T = int(sys.stdin.readline())
for _ in range(T):
	(N, K) = list(map(int, sys.stdin.readline().split()))
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes' if is_probable_prime(N) else 'No')
	elif K == 2:
		if N % 2 == 0:
			print('Yes')
		else:
			print('Yes' if is_probable_prime(N - 2) else 'No')
	else:
		print('Yes')


import math, random, sys

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	elif n & 1 == 0:
		return False
	else:
		(s, d) = (0, n - 1)
		while d & 1 == 0:
			(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True
T = int(sys.stdin.readline())
for _ in range(T):
	(N, K) = list(map(int, sys.stdin.readline().split()))
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes' if is_probable_prime(N) else 'No')
	elif K == 2:
		if N % 2 == 0:
			print('Yes')
		else:
			print('Yes' if is_probable_prime(N - 2) else 'No')
	else:
		print('Yes')


import math, random, sys

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	elif n & 1 == 0:
		return False
	else:
		(s, d) = (0, n - 1)
		while d & 1 == 0:
			(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True
T = int(sys.stdin.readline())
for _ in range(T):
	(N, K) = list(map(int, sys.stdin.readline().split()))
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes' if is_probable_prime(N) else 'No')
	elif K == 2:
		if N % 2 == 0:
			print('Yes')
		else:
			print('Yes' if is_probable_prime(N - 2) else 'No')
	else:
		print('Yes')


def _try_composite(a, d, n, s):
	if pow(a, d, n) == 1:
		return False
	for i in range(s):
		if pow(a, 2 ** i * d, n) == n - 1:
			return False
	return True
_known_primes = [2, 3]

def is_prime(n, _precision_for_huge_n=16):
	if n in _known_primes or n in (0, 1):
		return True
	if any((n % p == 0 for p in _known_primes)):
		return False
	(d, s) = (n - 1, 0)
	while not d % 2:
		(d, s) = (d >> 1, s + 1)
	if n < 1373653:
		return not any((_try_composite(a, d, n, s) for a in (2, 3)))
	if n < 25326001:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5)))
	if n < 118670087467:
		if n == 3215031751:
			return False
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7)))
	if n < 2152302898747:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11)))
	if n < 3474749660383:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13)))
	if n < 341550071728321:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13, 17)))
	return not any((_try_composite(a, d, n, s) for a in _known_primes[:_precision_for_huge_n]))

def primeSum(n, k):
	if n < 2 * k:
		return False
	elif k == 1 and is_prime(n):
		return True
	elif k == 2:
		if n % 2 == 0:
			return True
		elif is_prime(n - 2):
			return True
		else:
			return False
	elif k >= 3:
		return True
	else:
		return False

def main():
	t = int(input())
	for i in range(t):
		(n, k) = map(int, input().split())
		if primeSum(n, k):
			print('Yes')
		else:
			print('No')
main()


from sys import *
from fractions import *
from itertools import *
from random import *
from functools import *

def isqrt(n):
	if n == 0:
		return 0
	(x, y) = (n, (n + 1) // 2)
	while y < x:
		(x, y) = (y, (y + n // y) // 2)
	return x

def introot(n, r=2):
	if n < 0:
		return None if n % 2 == 0 else -introot(-n, r)
	if n < 2:
		return n
	if r == 2:
		return isqrt(n)
	(lo, hi) = (0, n)
	while lo != hi - 1:
		mid = (lo + hi) // 2
		m = pow(mid, r)
		if m == n:
			return mid
		if m < n:
			lo = mid
		else:
			hi = mid
	return lo

def primegen():
	yield 2
	yield 3
	yield 5
	yield 7
	yield 11
	yield 13
	ps = primegen()
	p = ps.__next__() and ps.__next__()
	(q, sieve, n) = (pow(p, 2), {}, 13)
	while True:
		if n not in sieve:
			if n < q:
				yield n
			else:
				(next, step) = (q + 2 * p, 2 * p)
				while next in sieve:
					next += step
				sieve[next] = step
				p = ps.__next__()
				q = pow(p, 2)
		else:
			step = sieve.pop(n)
			next = n + step
			while next in sieve:
				next += step
			sieve[next] = step
		n += 2

def primes(n):
	return list(takewhile(lambda p: p < n, primegen()))

def listprod(a):
	return reduce(lambda x, y: x * y, a, 1)

def jacobi(a, p):
	if p % 2 == 0 or p < 0:
		return None
	if a == 0 or a == 1:
		return a
	(a, t) = (a % p, 1)
	while a != 0:
		while not a & 1:
			a /= 2
			if p & 7 in (3, 5):
				t *= -1
		(a, p) = (p, a)
		if a & 3 == 3 and p & 3 == 3:
			t *= -1
		a %= p
	return t if p == 1 else 0

def chain(n, u1, v1, u2, v2, d, q, m):
	k = q
	while m > 0:
		(u2, v2, q) = (u2 * v2 % n, (v2 * v2 - 2 * q) % n, q * q % n)
		if m % 2 == 1:
			(u1, v1) = (u2 * v1 + u1 * v2, v2 * v1 + u2 * u1 * d)
			if u1 % 2 == 1:
				u1 = u1 + n
			if v1 % 2 == 1:
				v1 = v1 + n
			(u1, v1, k) = (u1 // 2 % n, v1 // 2 % n, q * k % n)
		m //= 2
	return (u1, v1, k)

def pfactor(n):
	(s, d, q) = (0, n - 1, 2)
	while not d & q - 1:
		(s, q) = (s + 1, q * 2)
	return (s, d // (q // 2))

def sprp(n, a, s=None, d=None):
	if n % 2 == 0:
		return False
	if s is None or d is None:
		(s, d) = pfactor(n)
	x = pow(a, d, n)
	if x == 1:
		return True
	for i in range(s):
		if x == n - 1:
			return True
		x = pow(x, 2, n)
	return False

def nextprime(n):
	if n < 2:
		return 2
	if n == 2:
		return 3
	n = n + 1 | 1
	m = n % 6
	if m == 3:
		if isprime(n + 2):
			return n + 2
		n += 4
	if m == 5:
		if isprime(n):
			return n
		n += 2
	for m in count(n, 6):
		if isprime(m):
			return m
		if isprime(m + 4):
			return m + 4

def isprime(n, tb=(3, 5, 7, 11), eb=(2,), mrb=()):
	if n % 2 == 0 or n < 13 or n == pow(isqrt(n), 2):
		return n in (2, 3, 5, 7, 11)
	if any((n % p == 0 for p in tb)):
		return n in tb
	for b in eb:
		if b >= n:
			continue
		if not pow(b, n - 1, n) == 1:
			return False
		r = n - 1
		while r % 2 == 0:
			r //= 2
		c = pow(b, r, n)
		if c == 1:
			continue
		while c != 1 and c != n - 1:
			c = pow(c, 2, n)
		if c == 1:
			return False
	(s, d) = pfactor(n)
	if not sprp(n, 2, s, d):
		return False
	if n < 2047:
		return True
	if n >= 3825123056546413051:
		d = 5
		while True:
			if gcd(d, n) > 1:
				(p, q) = (0, 0)
				break
			if jacobi(d, n) == -1:
				(p, q) = (1, (1 - d) // 4)
				break
			d = -d - 2 * d // abs(d)
		if p == 0:
			return n == d
		(s, t) = pfactor(n + 2)
		(u, v, u2, v2, m) = (1, p, 1, p, t // 2)
		k = q
		while m > 0:
			(u2, v2, q) = (u2 * v2 % n, (v2 * v2 - 2 * q) % n, q * q % n)
			if m % 2 == 1:
				(u, v) = (u2 * v + u * v2, v2 * v + u2 * u * d)
				if u % 2 == 1:
					u += n
				if v % 2 == 1:
					v += n
				(u, v, k) = (u // 2 % n, v // 2 % n, q * k % n)
			m //= 2
		if u == 0 or v == 0:
			return True
		for i in range(1, s):
			(v, k) = ((v * v - 2 * k) % n, k * k % n)
			if v == 0:
				return True
		return False
	if not mrb:
		if n < 1373653:
			mrb = [3]
		elif n < 25326001:
			mrb = [3, 5]
		elif n < 3215031751:
			mrb = [3, 5, 7]
		elif n < 2152302898747:
			mrb = [3, 5, 7, 11]
		elif n < 3474749660383:
			mrb = [3, 5, 6, 11, 13]
		elif n < 341550071728321:
			mrb = [3, 5, 7, 11, 13, 17]
		elif n < 3825123056546413051:
			mrb = [3, 5, 7, 11, 13, 17, 19, 23]
	return all((sprp(n, b, s, d) for b in mrb))

def ilog(x, b):
	l = 0
	while x >= b:
		x //= b
		l += 1
	return l

def ispower(n):
	for p in primegen():
		r = introot(n, p)
		if r is None:
			continue
		if r ** p == n:
			return r
		if r == 1:
			return 0

def pollardRho_brent(n):
	if isprime(n):
		return n
	g = n
	while g == n:
		(y, c, m, g, r, q) = (randrange(1, n), randrange(1, n), randrange(1, n), 1, 1, 1)
		while g == 1:
			(x, k) = (y, 0)
			for i in range(r):
				y = (y ** 2 + c) % n
			while k < r and g == 1:
				ys = y
				for i in range(min(m, r - k)):
					y = (y ** 2 + c) % n
					q = q * abs(x - y) % n
				(g, k) = (gcd(q, n), k + m)
			r *= 2
		if g == n:
			while True:
				ys = (ys ** 2 + c) % n
				g = gcd(abs(x - ys), n)
				if g > 1:
					break
	return g

def pollard_pm1(n, B1=100, B2=1000):
	if isprime(n):
		return n
	m = ispower(n)
	if m:
		return m
	while True:
		pg = primegen()
		q = 2
		p = pg.__next__()
		while p <= B1:
			(q, p) = (pow(q, p ** ilog(B1, p), n), pg.__next__())
		g = gcd(q - 1, n)
		if 1 < g < n:
			return g
		while p <= B2:
			(q, p) = (pow(q, p, n), pg.__next__())
		g = gcd(q - 1, n)
		if 1 < g < n:
			return g
		B1 *= 10
		B2 *= 10

def mlucas(v, a, n):
	(v1, v2) = (v, (v ** 2 - 2) % n)
	for bit in bin(a)[3:]:
		(v1, v2) = ((v1 ** 2 - 2) % n, (v1 * v2 - v) % n) if bit == '0' else ((v1 * v2 - v) % n, (v2 ** 2 - 2) % n)
	return v1

def williams_pp1(n):
	if isprime(n):
		return n
	m = ispower(n)
	if m:
		return m
	for v in count(1):
		for p in primegen():
			e = ilog(isqrt(n), p)
			if e == 0:
				break
			for _ in range(e):
				v = mlucas(v, p, n)
			g = gcd(v - 2, n)
			if 1 < g < n:
				return g
			if g == n:
				break

def ecadd(p1, p2, p0, n):
	(x1, z1) = p1
	(x2, z2) = p2
	(x0, z0) = p0
	(t1, t2) = ((x1 - z1) * (x2 + z2), (x1 + z1) * (x2 - z2))
	return (z0 * pow(t1 + t2, 2, n) % n, x0 * pow(t1 - t2, 2, n) % n)

def ecdub(p, A, n):
	(x, z) = p
	(An, Ad) = A
	(t1, t2) = (pow(x + z, 2, n), pow(x - z, 2, n))
	t = t1 - t2
	return (t1 * t2 * 4 * Ad % n, (4 * Ad * t2 + t * An) * t % n)

def ecmul(m, p, A, n):
	if m == 0:
		return (0, 0)
	elif m == 1:
		return p
	else:
		q = ecdub(p, A, n)
		if m == 2:
			return q
		b = 1
		while b < m:
			b *= 2
		b //= 4
		r = p
		while b:
			if m & b:
				(q, r) = (ecdub(q, A, n), ecadd(q, r, p, n))
			else:
				(q, r) = (ecadd(r, q, p, n), ecdub(r, A, n))
			b //= 2
		return r

def ecm(n, B1=10, B2=20):
	if isprime(n):
		return n
	m = ispower(n)
	if m:
		return m
	iters = 1
	while True:
		for _ in range(iters):
			seed = randrange(6, n)
			(u, v) = ((seed ** 2 - 5) % n, 4 * seed % n)
			p = pow(u, 3, n)
			(Q, C) = ((pow(v - u, 3, n) * (3 * u + v) % n, 4 * p * v % n), (p, pow(v, 3, n)))
			pg = primegen()
			p = pg.__next__()
			while p <= B1:
				(Q, p) = (ecmul(p ** ilog(B1, p), Q, C, n), pg.__next__())
			g = gcd(Q[1], n)
			if 1 < g < n:
				return g
			while p <= B2:
				Q = ecmul(p, Q, C, n)
				g *= Q[1]
				g %= n
				p = pg.__next__()
			g = gcd(g, n)
			if 1 < g < n:
				return g
		B1 *= 3
		B2 *= 3
		iters *= 2

def legendre1(a, p):
	return (pow(a, p - 1 >> 1, p) + 1) % p - 1

def legendre2(a, p):
	if a == 0:
		return 0
	(x, y, L) = (a, p, 1)
	while 1:
		if x > y >> 1:
			x = y - x
			if y & 3 == 3:
				L = -L
		while x & 3 == 0:
			x >>= 2
		if x & 1 == 0:
			x >>= 1
			if y & 7 == 3 or y & 7 == 5:
				L = -L
		if x == 1:
			return (L + 1) % p - 1
		if x & 3 == 3 and y & 3 == 3:
			L = -L
		(x, y) = (y % x, x)
legendre = legendre1

def mod_sqrt(n, p):
	a = n % p
	if p % 4 == 3:
		return pow(a, p + 1 >> 2, p)
	elif p % 8 == 5:
		v = pow(a << 1, p - 5 >> 3, p)
		i = (a * v * v << 1) % p - 1
		return a * v * i % p
	elif p % 8 == 1:
		(q, e) = (p - 1, 0)
		while q & 1 == 0:
			e += 1
			q >>= 1
		n = 2
		while legendre(n, p) != -1:
			n += 1
		(w, x, y, r) = (pow(a, q, p), pow(a, q + 1 >> 1, p), pow(n, q, p), e)
		while True:
			if w == 1:
				return x
			(v, k) = (w, 0)
			while v != 1 and k + 1 < r:
				v = v * v % p
				k += 1
			if k == 0:
				return x
			d = pow(y, 1 << r - k - 1, p)
			(x, y) = (x * d % p, d * d % p)
			(w, r) = (w * y % p, k)
	else:
		return a

def modinv(a, m):
	(a, x, u) = (a % m, 0, 1)
	while a:
		(x, u, m, a) = (u, x - m / a * u, a, m % a)
	return x

def mpqs(n):
	m = ispower(n)
	if m:
		return m
	if isprime(n):
		return n
	(root_n, root_2n) = (isqrt(n), isqrt(2 * n))
	bound = ilog(n ** 6, 10) ** 2
	while True:
		try:
			(prime, mod_root, log_p, num_prime) = ([], [], [], 0)
			p = 2
			while p < bound or num_prime < 3:
				leg = legendre(n % p, p)
				if leg == 1:
					prime += [p]
					mod_root += [mod_sqrt(n, p)]
					log_p += [log(p, 10)]
					num_prime += 1
				elif leg == 0:
					return p
				p = nextprime(p)
			x_max = len(prime) * 60
			m_val = x_max * root_2n >> 1
			thresh = log(m_val, 10) * 0.735
			min_prime = mpz(thresh * 3)
			fudge = sum((log_p[i] for (i, p) in enumerate(prime) if p < min_prime)) / 4
			thresh -= fudge
			(smooth, used_prime, partial) = ([], set(), {})
			(num_smooth, num_used_prime, num_partial, num_poly, root_A) = (0, 0, 0, 0, isqrt(root_2n // x_max))
			while num_smooth <= num_used_prime:
				while True:
					root_A = nextprime(root_A)
					leg = legendre(n, root_A)
					if leg == 1:
						break
					elif leg == 0:
						return root_A
				A = root_A ** 2
				b = mod_sqrt(n, root_A)
				B = (b + (n - b * b) * modinv(b + b, root_A)) % A
				C = (B * B - n) // A
				num_poly += 1
				(sums, i) = ([0.0] * (2 * x_max), 0)
				for p in prime:
					if p < min_prime:
						i += 1
						continue
					logp = log_p[i]
					inv_A = modinv(A, p)
					(a, b, k) = (mpz((mod_root[i] - B) * inv_A % p), mpz((p - mod_root[i] - B) * inv_A % p), 0)
					while k < x_max:
						if k + a < x_max:
							sums[k + a] += logp
						if k + b < x_max:
							sums[k + b] += logp
						if k:
							sums[k - a + x_max] += logp
							sums[k - b + x_max] += logp
						k += p
					i += 1
				i = 0
				for v in sums:
					if v > thresh:
						(x, vec, sqr) = (x_max - i if i > x_max else i, set(), [])
						val = sieve_val = (A * x + 2 * B) * x + C
						if sieve_val < 0:
							(vec, sieve_val) = ({-1}, -sieve_val)
						for p in prime:
							while sieve_val % p == 0:
								if p in vec:
									sqr += [p]
								vec ^= {p}
								sieve_val = mpz(sieve_val // p)
						if sieve_val == 1:
							smooth += [(vec, (sqr, A * x + B, root_A))]
							used_prime |= vec
						elif sieve_val in partial:
							(pair_vec, pair_vals) = partial[sieve_val]
							sqr += list(vec & pair_vec) + [sieve_val]
							vec ^= pair_vec
							smooth += [(vec, (sqr + pair_vals[0], (A * x + B) * pair_vals[1], root_A * pair_vals[2]))]
							used_prime |= vec
							num_partial += 1
						else:
							partial[sieve_val] = (vec, (sqr, A * x + B, root_A))
					i += 1
				(num_smooth, num_used_prime) = (len(smooth), len(used_prime))
			used_prime = sorted(list(used_prime))
			(masks, mask, bitfields) = ([], 1, [0] * num_used_prime)
			for (vec, vals) in smooth:
				masks += [mask]
				i = 0
				for p in used_prime:
					if p in vec:
						bitfields[i] |= mask
					i += 1
				mask <<= 1
			offset = 0
			null_cols = []
			for col in range(num_smooth):
				pivot = bitfields[col - offset] & masks[col] == 0
				for row in range(col + 1 - offset, num_used_prime):
					if bitfields[row] & masks[col]:
						if pivot:
							(bitfields[col - offset], bitfields[row], pivot) = (bitfields[row], bitfields[col - offset], False)
						else:
							bitfields[row] ^= bitfields[col - offset]
				if pivot:
					null_cols += [col]
					offset += 1
			for row in range(num_used_prime):
				mask = bitfields[row] & -bitfields[row]
				for up_row in range(row):
					if bitfields[up_row] & mask:
						bitfields[up_row] ^= bitfields[row]
			for col in null_cols:
				(all_vec, (lh, rh, rA)) = smooth[col]
				lhs = lh
				rhs = [rh]
				rAs = [rA]
				i = 0
				for field in bitfields:
					if field & masks[col]:
						(vec, (lh, rh, rA)) = smooth[i]
						lhs += list(all_vec & vec) + lh
						all_vec ^= vec
						rhs += [rh]
						rAs += [rA]
					i += 1
				factor = gcd(listprod(rAs) * listprod(lhs) - listprod(rhs), n)
				if 1 < factor < n:
					return factor
		except IndexError:
			pass
		bound *= 1.2

def primefac(n, trial_limit=1000, rho_rounds=42000, verbose=False, methods=(pollardRho_brent, pollard_pm1, williams_pp1, ecm, mpqs)):
	if n < 2:
		return
	if isprime(n):
		yield n
		return
	(factors, nroot) = ([], isqrt(n))
	for p in primegen():
		if n % p == 0:
			while n % p == 0:
				yield p
				n //= p
			nroot = isqrt(n)
			if isprime(n):
				yield n
				return
		if p > nroot:
			if n != 1:
				yield n
			return
		if p >= trial_limit:
			break
	if isprime(n):
		yield n
		return
	if rho_rounds == 'inf':
		factors = [n]
		while len(factors) != 0:
			n = min(factors)
			factors.remove(n)
			f = pollardRho_brent(n)
			if isprime(f):
				yield f
			else:
				factors.append(f)
			n //= f
			if isprime(n):
				yield n
			else:
				factors.append(n)
		return
	(factors, difficult) = ([n], [])
	while len(factors) != 0:
		rhocount = 0
		n = factors.pop()
		try:
			g = n
			while g == n:
				(x, c, g) = (randrange(1, n), randrange(1, n), 1)
				y = x
				while g == 1:
					if rhocount >= rho_rounds:
						raise Exception
					rhocount += 1
					x = (x ** 2 + c) % n
					y = (y ** 2 + c) % n
					y = (y ** 2 + c) % n
					g = gcd(x - y, n)
			if isprime(g):
				yield g
			else:
				factors.append(g)
			n //= g
			if isprime(n):
				yield n
			else:
				factors.append(n)
		except Exception:
			difficult.append(n)
	factors = difficult
	while len(factors) != 0:
		n = min(factors)
		factors.remove(n)
		f = multifactor(n, methods=methods, verbose=verbose)
		if isprime(f):
			yield f
		else:
			factors.append(f)
		n //= f
		if isprime(n):
			yield n
		else:
			factors.append(n)

def solve(n, k):
	if k == 1:
		return isprime(n)
	if k == 2:
		if n % 2 == 0:
			return n >= 4
		else:
			return isprime(n - 2)
	return n // 2 >= k
for _ in range(int(input())):
	print('Yes' if solve(*map(int, input().split())) else 'No')


import math

def _try_composite(a, d, n, s):
	if pow(a, d, n) == 1:
		return False
	for i in range(s):
		if pow(a, 2 ** i * d, n) == n - 1:
			return False
	return True

def is_prime(n, _precision_for_huge_n=16):
	if n == 1:
		return False
	if n in _known_primes or n in (0, 1):
		return True
	if any((n % p == 0 for p in _known_primes)):
		return False
	(d, s) = (n - 1, 0)
	while not d % 2:
		(d, s) = (d >> 1, s + 1)
	if n < 1373653:
		return not any((_try_composite(a, d, n, s) for a in (2, 3)))
	if n < 25326001:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5)))
	if n < 118670087467:
		if n == 3215031751:
			return False
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7)))
	if n < 2152302898747:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11)))
	if n < 3474749660383:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13)))
	if n < 341550071728321:
		return not any((_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13, 17)))
	return not any((_try_composite(a, d, n, s) for a in _known_primes[:_precision_for_huge_n]))

def solve(N, K):
	return (K - 2) * 2 < N - 2
_known_primes = [2, 3]
_known_primes += [x for x in range(5, 1000, 2) if is_prime(x)]
T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	f = False
	if K == 1:
		f = is_prime(N)
	elif K == 2:
		if N % 2 == 0:
			f = N > 2
		elif N <= 2:
			f = False
		else:
			f = is_prime(N - 2)
	elif N % 2 == 0:
		f = solve(N, K)
	else:
		f = solve(N - 3, K - 1)
	if f:
		print('Yes')
	else:
		print('No')


import random

def isprime(n):
	if n < 2:
		return False
	if n < 10 ** 5:
		return all((n % i for i in range(2, int(n ** 0.5) + 1)))
	for _ in range(20):
		a = random.randint(1, n - 1)
		if pow(a, n - 1, n) != 1:
			return False
	return True
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	if n < 2 * k:
		print('No')
	elif k == 1:
		print('Yes' if isprime(n) else 'No')
	elif k == 2:
		print('Yes' if n % 2 == 0 or isprime(n - 2) else 'No')
	else:
		print('Yes')


def bitize(x):
	L = []
	while x > 0:
		L.append(x % 2)
		x //= 2
	if not L:
		L.append(0)
	return L

def pow_mod(a, b, m):
	b_bits = bitize(b)
	a_powers = [0 for x in b_bits]
	a_powers[0] = a % m
	if b_bits[0]:
		total = a % m
	else:
		total = 1
	for i in range(1, len(b_bits)):
		a_powers[i] = a_powers[i - 1] * a_powers[i - 1] % m
		if b_bits[i]:
			total *= a_powers[i]
			total %= m
	return total % m

def is_miller_rabin(x, num_tests=3):
	k = x - 1
	e = 0
	while k % 2 == 0:
		e += 1
		k //= 2
	tests = [False for _ in range(0, num_tests)]
	A = [2, 3, 5]
	for j in range(3, num_tests):
		A.append(random.randint(7, x - 1))
	if x < 2047:
		num_tests = 1
	elif x < 1373653:
		num_tests = 2
	elif x < 25326001:
		num_tests = 3
	for i in range(0, num_tests):
		ak = pow_mod(A[i], k, x)
		if ak == 1:
			tests[i] = True
		else:
			for j in range(0, e):
				if ak == x - 1:
					tests[i] = True
				ak = ak * ak % x
	for i in range(0, num_tests):
		if not tests[i]:
			return False
	return True

def is_prime(x, L=[]):
	sqrt = int(pow(x, 0.5)) + 1
	PL = [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]
	if not L:
		if x < 210:
			if x in PL:
				return True
			else:
				return False
		else:
			for p in PL:
				if x % p == 0:
					return False
			for i in range(1, sqrt // 210 + 1):
				for j in [1, 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, 121, 127, 131, 137, 139, 143, 149, 151, 157, 163, 167, 169, 173, 179, 181, 187, 191, 193, 197, 199, 209]:
					if x % (210 * i + j) == 0:
						return False
		return True
	elif x != 0 and x != 1:
		j = 0
		while j < len(L) and L[j] <= sqrt:
			if x % L[j] == 0:
				return False
			j += 1
	else:
		return False
	return True
T = int(input())
for _ in range(0, T):
	(N, K) = [int(a) for a in input().split()]
	if N == 1:
		print('No')
	elif N == 2 and K == 1:
		print('Yes')
	elif N == 3:
		if K == 1:
			print('Yes')
		else:
			print('No')
	elif N > 4 and N % 2 == 0 and (2 <= K <= N // 2):
		print('Yes')
	elif N > 4 and N % 2 and (2 <= K - 1 <= (N - 3) // 2):
		print('Yes')
	elif (N == 3 or N == 2) and K == 1:
		print('Yes')
	elif K == 1:
		if N < 100000 and is_prime(N):
			print('Yes')
		elif is_miller_rabin(N):
			print('Yes')
		else:
			print('No')
	elif K == 2:
		if N % 2:
			if N < 100000 and is_prime(N - 2):
				print('Yes')
			elif N % 2 and is_miller_rabin(N - 2):
				print('Yes')
			else:
				print('No')
		elif N > 2 and N % 2 == 0:
			print('Yes')
		else:
			print('No')
	else:
		print('No')


import random
import sys

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	if n & 1 == 0:
		return False
	(s, d) = (0, n - 1)
	while d & 1 == 0:
		(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True

def f(n, k):
	if n < 2 * k:
		return False
	if k == 1:
		return is_probable_prime(n)
	if k == 2:
		if n % 2 == 0:
			return True
		else:
			return is_probable_prime(n - 2)
	return True
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print('Yes' if f(n, k) else 'No')


from random import randrange

def miller_rabin(n, k=10):
	if n == 2:
		return True
	if n & 1 == 0:
		return False

	def check(a, s, d, n):
		x = pow(a, d, n)
		if x == 1:
			return True
		for i in range(s - 1):
			if x == n - 1:
				return True
			x = pow(x, 2, n)
		return x == n - 1
	s = 0
	d = n - 1
	while d % 2 == 0:
		d >>= 1
		s += 1
	for i in range(k):
		a = randrange(2, n - 1)
		if not check(a, s, d, n):
			return False
	return True

class Crible:

	def __init__(self, n_max):
		self.n_max = n_max
		self.maximum = n = (n_max - 3) // 2 + 1
		self.crible = crible = [False] * (n + 1)
		self._premiers = None
		self._phi = None
		i = 0
		while i < n:
			while i < n:
				if not crible[i]:
					break
				i += 1
			k = 3
			while True:
				j = k * i + 3 * (k - 1) // 2
				if j >= n:
					break
				crible[j] = True
				k += 2
			i += 1

	def est_premier(self, n):
		if n == 2:
			return True
		elif n % 2 == 0 or n <= 1:
			return False
		else:
			assert n < self.n_max
			return not self.crible[(n - 3) // 2]
N = 1000000
sieve = Crible(N)

def is_prime(n):
	if n < N:
		return sieve.est_premier(n)
	else:
		return miller_rabin(n)

def check(n, k):
	if k == 1:
		print('Yes' if is_prime(n) else 'No')
	elif n < 4:
		print('No')
	elif k == 2 and n % 2 == 1:
		print('Yes' if is_prime(n - 2) else 'No')
	elif n % 2 == 0:
		print('Yes' if k <= n // 2 else 'No')
	else:
		print('Yes' if k - 1 <= (n - 3) // 2 else 'No')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	check(n, k)


import random

def isprime(n):
	if n <= 1 or n == 4:
		return False
	if n <= 3:
		return True
	k = 10
	while k:
		a = 2 + random.randint(1, n - 4)
		if pow(a, n - 1, n) != 1:
			return False
		k -= 1
	return True
for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	if n < 2 * k:
		print('No')
	elif k == 1:
		print('Yes' if isprime(n) else 'No')
	elif k == 2 and n & 1:
		print('Yes' if isprime(n - 2) else 'No')
	elif k == 2 and n & 1 == 0:
		print('Yes')
	elif k >= 3 and n >= 2 * k:
		print('Yes')


import random

def isprime(n):
	if n <= 1 or n == 4:
		return False
	if n <= 3:
		return True
	k = 10
	while k:
		a = 2 + random.randint(1, n - 4)
		if pow(a, n - 1, n) != 1:
			return False
		k -= 1
	return True
for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	if n < 2 * k:
		print('No')
	elif k == 1:
		print('Yes' if isprime(n) else 'No')
	elif k == 2 and n & 1:
		print('Yes' if isprime(n - 2) else 'No')
	elif k == 2 and n & 1 == 0:
		print('Yes')
	elif k >= 3 and n >= 2 * k:
		print('Yes')


import os
import sys
from random import randrange

def miller_rabin(n, k=10):
	if n == 2:
		return True
	if n & 1 == 0:
		return False

	def check(a, s, d, n):
		x = pow(a, d, n)
		if x == 1:
			return True
		for i in range(s - 1):
			if x == n - 1:
				return True
			x = pow(x, 2, n)
		return x == n - 1
	s = 0
	d = n - 1
	while d % 2 == 0:
		d >>= 1
		s += 1
	for i in range(k):
		a = randrange(2, n - 1)
		if not check(a, s, d, n):
			return False
	return True

class Crible:

	def __init__(self, n_max):
		self.n_max = n_max
		self.maximum = n = (n_max - 3) // 2 + 1
		self.crible = crible = [False] * (n + 1)
		self._premiers = None
		self._phi = None
		i = 0
		while i < n:
			while i < n:
				if not crible[i]:
					break
				i += 1
			k = 3
			while True:
				j = k * i + 3 * (k - 1) // 2
				if j >= n:
					break
				crible[j] = True
				k += 2
			i += 1

	def est_premier(self, n):
		if n == 2:
			return True
		elif n % 2 == 0 or n <= 1:
			return False
		else:
			assert n < self.n_max
			return not self.crible[(n - 3) // 2]
N = 1000000
sieve = Crible(N)

def is_prime(n):
	if n < N:
		return sieve.est_premier(n)
	else:
		return miller_rabin(n)

def check(n, k):
	if k == 1:
		print('Yes' if is_prime(n) else 'No')
	elif n < 4:
		print('No')
	elif k == 2 and n % 2 == 1:
		print('Yes' if is_prime(n - 2) else 'No')
	elif n % 2 == 0:
		print('Yes' if k <= n // 2 else 'No')
	else:
		print('Yes' if k - 1 <= (n - 3) // 2 else 'No')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	check(n, k)


def witness(a, n, b):
	d = 1
	for i in range(len(b) - 1, -1, -1):
		x = d
		d = d * d % n
		if d == 1 and x != 1 and (x != n - 1):
			return True
		if b[i] == 1:
			d = d * a % n
	return d != 1

def miller_rabin(n):
	if n < 2:
		return False
	m = n - 1
	b = []
	while m:
		b.append(m & 1)
		m >>= 1
	for w in (2, 325, 9375, 28178, 450775, 9780504, 1795265022):
		if w % n != 0 and witness(w, n, b):
			return False
	return True

def prime_sum(N, K):
	if N < 2 * K:
		return False
	elif K == 1:
		return miller_rabin(N)
	elif N % 2 == 0 or K >= 3:
		return True
	else:
		return miller_rabin(N - 2)
T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	print('Yes' if prime_sum(N, K) else 'No')


from random import randrange

def miller_rabin(n, k=10):
	if n == 2:
		return True
	if n & 1 == 0:
		return False

	def check(a, s, d, n):
		x = pow(a, d, n)
		if x == 1:
			return True
		for i in range(s - 1):
			if x == n - 1:
				return True
			x = pow(x, 2, n)
		return x == n - 1
	s = 0
	d = n - 1
	while d % 2 == 0:
		d >>= 1
		s += 1
	for i in range(k):
		a = randrange(2, n - 1)
		if not check(a, s, d, n):
			return False
	return True

class Crible:

	def __init__(self, n_max):
		self.n_max = n_max
		self.maximum = n = (n_max - 3) // 2 + 1
		self.crible = crible = [False] * (n + 1)
		self._premiers = None
		self._phi = None
		i = 0
		while i < n:
			while i < n:
				if not crible[i]:
					break
				i += 1
			k = 3
			while True:
				j = k * i + 3 * (k - 1) // 2
				if j >= n:
					break
				crible[j] = True
				k += 2
			i += 1

	def est_premier(self, n):
		if n == 2:
			return True
		elif n % 2 == 0 or n <= 1:
			return False
		else:
			assert n < self.n_max
			return not self.crible[(n - 3) // 2]
N = 1000000
sieve = Crible(N)

def is_prime(n):
	if n < N:
		return sieve.est_premier(n)
	else:
		return miller_rabin(n)

def check(n, k):
	if k == 1:
		print('Yes' if is_prime(n) else 'No')
	elif n < 4:
		print('No')
	elif k == 2 and n % 2 == 1:
		print('Yes' if is_prime(n - 2) else 'No')
	elif n % 2 == 0:
		print('Yes' if k <= n // 2 else 'No')
	else:
		print('Yes' if k - 1 <= (n - 3) // 2 else 'No')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	check(n, k)


import random

def prime(n):
	if n < 2:
		return False
	if n < 10 ** 5:
		return all((n % i for i in range(2, int(n ** 0.5) + 1)))
	for _ in range(20):
		a = random.randint(1, n - 1)
		if pow(a, n - 1, n) != 1:
			return False
	return True
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	if n < 2 * k:
		print('No')
	elif k == 1:
		print('Yes' if prime(n) else 'No')
	elif k == 2:
		print('Yes' if n % 2 == 0 or prime(n - 2) else 'No')
	else:
		print('Yes')


import random

def isprime(n):
	if n <= 1 or n == 4:
		return False
	if n <= 3:
		return True
	k = 10
	while k:
		a = 2 + random.randint(1, n - 4)
		if pow(a, n - 1, n) != 1:
			return False
		k -= 1
	return True
for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	if n < 2 * k:
		print('No')
	elif k == 1:
		print('Yes' if isprime(n) else 'No')
	elif k == 2 and n & 1:
		print('Yes' if isprime(n - 2) else 'No')
	elif k == 2 and n & 1 == 0:
		print('Yes')
	elif k >= 3 and n >= 2 * k:
		print('Yes')


import random

def isprime(n):
	if n <= 1 or n == 4:
		return False
	if n <= 3:
		return True
	k = 10
	while k:
		a = 2 + random.randint(1, n - 4)
		if pow(a, n - 1, n) != 1:
			return False
		k -= 1
	return True
for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	if n < 2 * k:
		print('No')
	elif k == 1:
		print('Yes' if isprime(n) else 'No')
	elif k == 2 and n & 1:
		print('Yes' if isprime(n - 2) else 'No')
	elif k == 2 and n & 1 == 0:
		print('Yes')
	elif k >= 3 and n >= 2 * k:
		print('Yes')


import random
import sys

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	if n & 1 == 0:
		return False
	(s, d) = (0, n - 1)
	while d & 1 == 0:
		(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True

def f(n, k):
	if n < 2 * k:
		return False
	if k == 1:
		return is_probable_prime(n)
	if k == 2:
		if n % 2 == 0:
			return True
		else:
			return is_probable_prime(n - 2)
	return True
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print('Yes' if f(n, k) else 'No')


import math, random, sys

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	elif n & 1 == 0:
		return False
	else:
		(s, d) = (0, n - 1)
		while d & 1 == 0:
			(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True
T = int(sys.stdin.readline())
for _ in range(T):
	(N, K) = list(map(int, sys.stdin.readline().split()))
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes' if is_probable_prime(N) else 'No')
	elif K == 2:
		if N % 2 == 0:
			print('Yes')
		else:
			print('Yes' if is_probable_prime(N - 2) else 'No')
	else:
		print('Yes')


from random import randrange

def miller_rabin(n, k=10):
	if n == 2:
		return True
	if n & 1 == 0:
		return False

	def check(a, s, d, n):
		x = pow(a, d, n)
		if x == 1:
			return True
		for i in range(s - 1):
			if x == n - 1:
				return True
			x = pow(x, 2, n)
		return x == n - 1
	s = 0
	d = n - 1
	while d % 2 == 0:
		d >>= 1
		s += 1
	for i in range(k):
		a = randrange(2, n - 1)
		if not check(a, s, d, n):
			return False
	return True

class Crible:

	def __init__(self, n_max):
		self.n_max = n_max
		self.maximum = n = (n_max - 3) // 2 + 1
		self.crible = crible = [False] * (n + 1)
		self._premiers = None
		self._phi = None
		i = 0
		while i < n:
			while i < n:
				if not crible[i]:
					break
				i += 1
			k = 3
			while True:
				j = k * i + 3 * (k - 1) // 2
				if j >= n:
					break
				crible[j] = True
				k += 2
			i += 1

	def est_premier(self, n):
		if n == 2:
			return True
		elif n % 2 == 0 or n <= 1:
			return False
		else:
			assert n < self.n_max
			return not self.crible[(n - 3) // 2]
N = 1000000
sieve = Crible(N)

def is_prime(n):
	if n < N:
		return sieve.est_premier(n)
	else:
		return miller_rabin(n)

def check(n, k):
	if k == 1:
		print('Yes' if is_prime(n) else 'No')
	elif n < 4:
		print('No')
	elif k == 2 and n % 2 == 1:
		print('Yes' if is_prime(n - 2) else 'No')
	elif n % 2 == 0:
		print('Yes' if k <= n // 2 else 'No')
	else:
		print('Yes' if k - 1 <= (n - 3) // 2 else 'No')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	check(n, k)


from random import randint

def prime(n):
	if n < 4:
		return n == 2 or n == 3
	for i in range(5):
		a = randint(2, n - 2)
		if pow(a, n - 1, n) != 1:
			return False
	return True

def solve(n, k):
	if n < 2 * k:
		return 'No'
	elif k == 1:
		if prime(n):
			return 'Yes'
		else:
			return 'No'
	elif k == 2:
		if n & 1:
			if prime(n - 2):
				return 'Yes'
			else:
				return 'No'
		else:
			return 'Yes'
	else:
		return 'Yes'
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(solve(n, k))


from random import randrange

def miller_rabin(n, k=10):
	if n == 2:
		return True
	if n & 1 == 0:
		return False

	def check(a, s, d, n):
		x = pow(a, d, n)
		if x == 1:
			return True
		for i in range(s - 1):
			if x == n - 1:
				return True
			x = pow(x, 2, n)
		return x == n - 1
	s = 0
	d = n - 1
	while d % 2 == 0:
		d >>= 1
		s += 1
	for i in range(k):
		a = randrange(2, n - 1)
		if not check(a, s, d, n):
			return False
	return True

class Crible:

	def __init__(self, n_max):
		self.n_max = n_max
		self.maximum = n = (n_max - 3) // 2 + 1
		self.crible = crible = [False] * (n + 1)
		self._premiers = None
		self._phi = None
		i = 0
		while i < n:
			while i < n:
				if not crible[i]:
					break
				i += 1
			k = 3
			while True:
				j = k * i + 3 * (k - 1) // 2
				if j >= n:
					break
				crible[j] = True
				k += 2
			i += 1

	def est_premier(self, n):
		if n == 2:
			return True
		elif n % 2 == 0 or n <= 1:
			return False
		else:
			assert n < self.n_max
			return not self.crible[(n - 3) // 2]
N = 1000000
sieve = Crible(N)

def is_prime(n):
	if n < N:
		return sieve.est_premier(n)
	else:
		return miller_rabin(n)

def check(n, k):
	if k == 1:
		print('Yes' if is_prime(n) else 'No')
	elif n < 4:
		print('No')
	elif k == 2 and n % 2 == 1:
		print('Yes' if is_prime(n - 2) else 'No')
	elif n % 2 == 0:
		print('Yes' if k <= n // 2 else 'No')
	else:
		print('Yes' if k - 1 <= (n - 3) // 2 else 'No')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	check(n, k)


import os
import sys
from random import randint

def prime(n):
	if n < 4:
		return n == 2 or n == 3
	for i in range(5):
		a = randint(2, n - 2)
		if pow(a, n - 1, n) != 1:
			return False
	return True

def solve(n, k):
	if n < 2 * k:
		return 'No'
	elif k == 1:
		if prime(n):
			return 'Yes'
		else:
			return 'No'
	elif k == 2:
		if n & 1:
			if prime(n - 2):
				return 'Yes'
			else:
				return 'No'
		else:
			return 'Yes'
	else:
		return 'Yes'
for i in range(int(input())):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	print(solve(n, k))


from random import randrange

def miller_rabin(n, k=10):
	if n == 2:
		return True
	if n & 1 == 0:
		return False

	def check(a, s, d, n):
		x = pow(a, d, n)
		if x == 1:
			return True
		for i in range(s - 1):
			if x == n - 1:
				return True
			x = pow(x, 2, n)
		return x == n - 1
	s = 0
	d = n - 1
	while d % 2 == 0:
		d >>= 1
		s += 1
	for i in range(k):
		a = randrange(2, n - 1)
		if not check(a, s, d, n):
			return False
	return True

class Crible:

	def __init__(self, n_max):
		self.n_max = n_max
		self.maximum = n = (n_max - 3) // 2 + 1
		self.crible = crible = [False] * (n + 1)
		self._premiers = None
		self._phi = None
		i = 0
		while i < n:
			while i < n:
				if not crible[i]:
					break
				i += 1
			k = 3
			while True:
				j = k * i + 3 * (k - 1) // 2
				if j >= n:
					break
				crible[j] = True
				k += 2
			i += 1

	def est_premier(self, n):
		if n == 2:
			return True
		elif n % 2 == 0 or n <= 1:
			return False
		else:
			assert n < self.n_max
			return not self.crible[(n - 3) // 2]
N = 1000000
sieve = Crible(N)

def is_prime(n):
	if n < N:
		return sieve.est_premier(n)
	else:
		return miller_rabin(n)

def check(n, k):
	if k == 1:
		print('Yes' if is_prime(n) else 'No')
	elif n < 4:
		print('No')
	elif k == 2 and n % 2 == 1:
		print('Yes' if is_prime(n - 2) else 'No')
	elif n % 2 == 0:
		print('Yes' if k <= n // 2 else 'No')
	else:
		print('Yes' if k - 1 <= (n - 3) // 2 else 'No')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	check(n, k)


from random import randrange

def miller_rabin(n, k=10):
	if n == 2:
		return True
	if n & 1 == 0:
		return False

	def check(a, s, d, n):
		x = pow(a, d, n)
		if x == 1:
			return True
		for i in range(s - 1):
			if x == n - 1:
				return True
			x = pow(x, 2, n)
		return x == n - 1
	s = 0
	d = n - 1
	while d % 2 == 0:
		d >>= 1
		s += 1
	for i in range(k):
		a = randrange(2, n - 1)
		if not check(a, s, d, n):
			return False
	return True

class Crible:

	def __init__(self, n_max):
		self.n_max = n_max
		self.maximum = n = (n_max - 3) // 2 + 1
		self.crible = crible = [False] * (n + 1)
		self._premiers = None
		self._phi = None
		i = 0
		while i < n:
			while i < n:
				if not crible[i]:
					break
				i += 1
			k = 3
			while True:
				j = k * i + 3 * (k - 1) // 2
				if j >= n:
					break
				crible[j] = True
				k += 2
			i += 1

	def est_premier(self, n):
		if n == 2:
			return True
		elif n % 2 == 0 or n <= 1:
			return False
		else:
			assert n < self.n_max
			return not self.crible[(n - 3) // 2]
N = 1000000
sieve = Crible(N)

def is_prime(n):
	if n < N:
		return sieve.est_premier(n)
	else:
		return miller_rabin(n)

def check(n, k):
	if k == 1:
		print('Yes' if is_prime(n) else 'No')
	elif n < 4:
		print('No')
	elif k == 2 and n % 2 == 1:
		print('Yes' if is_prime(n - 2) else 'No')
	elif n % 2 == 0:
		print('Yes' if k <= n // 2 else 'No')
	else:
		print('Yes' if k - 1 <= (n - 3) // 2 else 'No')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	check(n, k)


import random

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	if n & 1 == 0:
		return False
	(s, d) = (0, n - 1)
	while d & 1 == 0:
		(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True

def f(n, k):
	if n < 2 * k:
		return False
	if k == 1:
		return is_probable_prime(n)
	if k == 2:
		if n % 2 == 0:
			return True
		else:
			return is_probable_prime(n - 2)
	return True
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print('Yes' if f(n, k) else 'No')


import random

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	if n & 1 == 0:
		return False
	(s, d) = (0, n - 1)
	while d & 1 == 0:
		(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True

def f(n, k):
	if n < 2 * k:
		return False
	if k == 1:
		return is_probable_prime(n)
	if k == 2:
		if n % 2 == 0:
			return True
		else:
			return is_probable_prime(n - 2)
	return True
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print('Yes' if f(n, k) else 'No')


from random import randrange

def miller_rabin(n, k=10):
	if n == 2:
		return True
	if n & 1 == 0:
		return False

	def check(a, s, d, n):
		x = pow(a, d, n)
		if x == 1:
			return True
		for i in range(s - 1):
			if x == n - 1:
				return True
			x = pow(x, 2, n)
		return x == n - 1
	s = 0
	d = n - 1
	while d % 2 == 0:
		d >>= 1
		s += 1
	for i in range(k):
		a = randrange(2, n - 1)
		if not check(a, s, d, n):
			return False
	return True

class Crible:

	def __init__(self, n_max):
		self.n_max = n_max
		self.maximum = n = (n_max - 3) // 2 + 1
		self.crible = crible = [False] * (n + 1)
		self._premiers = None
		self._phi = None
		i = 0
		while i < n:
			while i < n:
				if not crible[i]:
					break
				i += 1
			k = 3
			while True:
				j = k * i + 3 * (k - 1) // 2
				if j >= n:
					break
				crible[j] = True
				k += 2
			i += 1

	def est_premier(self, n):
		if n == 2:
			return True
		elif n % 2 == 0 or n <= 1:
			return False
		else:
			assert n < self.n_max
			return not self.crible[(n - 3) // 2]
N = 1000000
sieve = Crible(N)

def is_prime(n):
	if n < N:
		return sieve.est_premier(n)
	else:
		return miller_rabin(n)

def check(n, k):
	if k == 1:
		print('Yes' if is_prime(n) else 'No')
	elif n < 4:
		print('No')
	elif k == 2 and n % 2 == 1:
		print('Yes' if is_prime(n - 2) else 'No')
	elif n % 2 == 0:
		print('Yes' if k <= n // 2 else 'No')
	else:
		print('Yes' if k - 1 <= (n - 3) // 2 else 'No')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	check(n, k)


import random

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	if n & 1 == 0:
		return False
	(s, d) = (0, n - 1)
	while d & 1 == 0:
		(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True

def f(n, k):
	if n < 2 * k:
		return False
	if k == 1:
		return is_probable_prime(n)
	if k == 2:
		if n % 2 == 0:
			return True
		else:
			return is_probable_prime(n - 2)
	return True
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print('Yes' if f(n, k) else 'No')


import math
import os
import random
import re
import sys

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	if n & 1 == 0:
		return False
	(s, d) = (0, n - 1)
	while d & 1 == 0:
		(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True

def f(n, k):
	if n < 2 * k:
		return False
	if k == 1:
		return is_probable_prime(n)
	if k == 2:
		if n % 2 == 0:
			return True
		else:
			return is_probable_prime(n - 2)
	return True
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print('Yes' if f(n, k) else 'No')


import random

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	if n & 1 == 0:
		return False
	(s, d) = (0, n - 1)
	while d & 1 == 0:
		(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True

def f(n, k):
	if n < 2 * k:
		return False
	if k == 1:
		return is_probable_prime(n)
	if k == 2:
		if n % 2 == 0:
			return True
		else:
			return is_probable_prime(n - 2)
	return True
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print('Yes' if f(n, k) else 'No')


import random

def fermatPrime(p):
	if p == 1 or p == 4:
		return False
	elif p == 2 or p == 3:
		return True
	else:
		for i in range(5):
			a = random.randint(2, p - 2)
			if pow(a, p - 1, p) != 1:
				return False
		return True
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes') if fermatPrime(N) else print('No')
	elif K == 2 and N % 2 == 0:
		print('Yes')
	elif K == 2 and N % 2 != 0:
		print('Yes') if fermatPrime(N - 2) else print('No')
	else:
		print('Yes')


import random

def fermatPrime(p):
	if p == 1 or p == 4:
		return False
	elif p == 2 or p == 3:
		return True
	else:
		for i in range(5):
			a = random.randint(2, p - 2)
			if pow(a, p - 1, p) != 1:
				return False
		return True
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes') if fermatPrime(N) else print('No')
	elif K == 2 and N % 2 == 0:
		print('Yes')
	elif K == 2 and N % 2 != 0:
		print('Yes') if fermatPrime(N - 2) else print('No')
	else:
		print('Yes')


import random

def fermatPrime(p):
	if p == 1 or p == 4:
		return False
	elif p == 2 or p == 3:
		return True
	else:
		for i in range(5):
			a = random.randint(2, p - 2)
			if pow(a, p - 1, p) != 1:
				return False
		return True
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes') if fermatPrime(N) else print('No')
	elif K == 2 and N % 2 == 0:
		print('Yes')
	elif K == 2 and N % 2 != 0:
		print('Yes') if fermatPrime(N - 2) else print('No')
	else:
		print('Yes')


import random

def fermatPrime(p):
	if p == 1 or p == 4:
		return False
	elif p == 2 or p == 3:
		return True
	else:
		for i in range(5):
			a = random.randint(2, p - 2)
			if pow(a, p - 1, p) != 1:
				return False
		return True
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes') if fermatPrime(N) else print('No')
	elif K == 2 and N % 2 == 0:
		print('Yes')
	elif K == 2 and N % 2 != 0:
		print('Yes') if fermatPrime(N - 2) else print('No')
	else:
		print('Yes')


import random

def fermatPrime(p):
	if p == 1 or p == 4:
		return False
	elif p == 2 or p == 3:
		return True
	else:
		for i in range(5):
			a = random.randint(2, p - 2)
			if pow(a, p - 1, p) != 1:
				return False
		return True
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes') if fermatPrime(N) else print('No')
	elif K == 2 and N % 2 == 0:
		print('Yes')
	elif K == 2 and N % 2 != 0:
		print('Yes') if fermatPrime(N - 2) else print('No')
	else:
		print('Yes')


import random

def fermatPrime(p):
	if p == 1 or p == 4:
		return False
	elif p == 2 or p == 3:
		return True
	else:
		for i in range(5):
			a = random.randint(2, p - 2)
			if pow(a, p - 1, p) != 1:
				return False
		return True
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes') if fermatPrime(N) else print('No')
	elif K == 2 and N % 2 == 0:
		print('Yes')
	elif K == 2 and N % 2 != 0:
		print('Yes') if fermatPrime(N - 2) else print('No')
	else:
		print('Yes')


import random

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	if n & 1 == 0:
		return False
	(s, d) = (0, n - 1)
	while d & 1 == 0:
		(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True

def f(n, k):
	if n < 2 * k:
		return False
	if k == 1:
		return is_probable_prime(n)
	if k == 2:
		if n % 2 == 0:
			return True
		else:
			return is_probable_prime(n - 2)
	return True
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print('Yes' if f(n, k) else 'No')


import random

def fermatPrime(p):
	if p == 1 or p == 4:
		return False
	elif p == 2 or p == 3:
		return True
	else:
		for i in range(5):
			a = random.randint(2, p - 2)
			if pow(a, p - 1, p) != 1:
				return False
		return True
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes') if fermatPrime(N) else print('No')
	elif K == 2 and N % 2 == 0:
		print('Yes')
	elif K == 2 and N % 2 != 0:
		print('Yes') if fermatPrime(N - 2) else print('No')
	else:
		print('Yes')


import random

def fermatPrime(p):
	if p == 1 or p == 4:
		return False
	elif p == 2 or p == 3:
		return True
	else:
		for i in range(5):
			a = random.randint(2, p - 2)
			if pow(a, p - 1, p) != 1:
				return False
		return True
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes') if fermatPrime(N) else print('No')
	elif K == 2 and N % 2 == 0:
		print('Yes')
	elif K == 2 and N % 2 != 0:
		print('Yes') if fermatPrime(N - 2) else print('No')
	else:
		print('Yes')


import random

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	if n & 1 == 0:
		return False
	(s, d) = (0, n - 1)
	while d & 1 == 0:
		(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True

def f(n, k):
	if n < 2 * k:
		return False
	if k == 1:
		return is_probable_prime(n)
	if k == 2:
		if n % 2 == 0:
			return True
		else:
			return is_probable_prime(n - 2)
	return True
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print('Yes' if f(n, k) else 'No')


import random

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	if n & 1 == 0:
		return False
	(s, d) = (0, n - 1)
	while d & 1 == 0:
		(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True

def f(n, k):
	if n < 2 * k:
		return False
	if k == 1:
		return is_probable_prime(n)
	if k == 2:
		if n % 2 == 0:
			return True
		else:
			return is_probable_prime(n - 2)
	return True
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print('Yes' if f(n, k) else 'No')


import random

def fermatPrime(p):
	if p == 1 or p == 4:
		return False
	elif p == 2 or p == 3:
		return True
	else:
		for i in range(5):
			a = random.randint(2, p - 2)
			if pow(a, p - 1, p) != 1:
				return False
		return True
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes') if fermatPrime(N) else print('No')
	elif K == 2 and N % 2 == 0:
		print('Yes')
	elif K == 2 and N % 2 != 0:
		print('Yes') if fermatPrime(N - 2) else print('No')
	else:
		print('Yes')


import random

def fermatPrime(p):
	if p == 1 or p == 4:
		return False
	elif p == 2 or p == 3:
		return True
	else:
		for i in range(5):
			a = random.randint(2, p - 2)
			if pow(a, p - 1, p) != 1:
				return False
		return True
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes') if fermatPrime(N) else print('No')
	elif K == 2 and N % 2 == 0:
		print('Yes')
	elif K == 2 and N % 2 != 0:
		print('Yes') if fermatPrime(N - 2) else print('No')
	else:
		print('Yes')


import random

def fermatPrime(p):
	if p == 1 or p == 4:
		return False
	elif p == 2 or p == 3:
		return True
	else:
		for i in range(5):
			a = random.randint(2, p - 2)
			if pow(a, p - 1, p) != 1:
				return False
		return True
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes') if fermatPrime(N) else print('No')
	elif K == 2 and N % 2 == 0:
		print('Yes')
	elif K == 2 and N % 2 != 0:
		print('Yes') if fermatPrime(N - 2) else print('No')
	else:
		print('Yes')


import random

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	if n & 1 == 0:
		return False
	(s, d) = (0, n - 1)
	while d & 1 == 0:
		(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True

def f(n, k):
	if n < 2 * k:
		return False
	if k == 1:
		return is_probable_prime(n)
	if k == 2:
		if n % 2 == 0:
			return True
		else:
			return is_probable_prime(n - 2)
	return True
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print('Yes' if f(n, k) else 'No')


import random

def fermatPrime(p):
	if p == 1 or p == 4:
		return False
	elif p == 2 or p == 3:
		return True
	else:
		for i in range(5):
			a = random.randint(2, p - 2)
			if pow(a, p - 1, p) != 1:
				return False
		return True
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes') if fermatPrime(N) else print('No')
	elif K == 2 and N % 2 == 0:
		print('Yes')
	elif K == 2 and N % 2 != 0:
		print('Yes') if fermatPrime(N - 2) else print('No')
	else:
		print('Yes')


import random

def is_probable_prime(n, k=7):
	if n < 6:
		return [False, False, True, True, False, True][n]
	if n & 1 == 0:
		return False
	(s, d) = (0, n - 1)
	while d & 1 == 0:
		(s, d) = (s + 1, d >> 1)
	for a in random.sample(range(2, n - 2), min(n - 4, k)):
		x = pow(a, d, n)
		if x != 1 and x + 1 != n:
			for r in range(1, s):
				x = pow(x, 2, n)
				if x == 1:
					return False
				elif x == n - 1:
					a = 0
					break
			if a:
				return False
	return True

def f(n, k):
	if n < 2 * k:
		return False
	if k == 1:
		return is_probable_prime(n)
	if k == 2:
		if n % 2 == 0:
			return True
		else:
			return is_probable_prime(n - 2)
	return True
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print('Yes' if f(n, k) else 'No')


import random

def fermatPrime(p):
	if p == 1 or p == 4:
		return False
	elif p == 2 or p == 3:
		return True
	else:
		for i in range(5):
			a = random.randint(2, p - 2)
			if pow(a, p - 1, p) != 1:
				return False
		return True
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes') if fermatPrime(N) else print('No')
	elif K == 2 and N % 2 == 0:
		print('Yes')
	elif K == 2 and N % 2 != 0:
		print('Yes') if fermatPrime(N - 2) else print('No')
	else:
		print('Yes')


import random

def fermatPrime(p):
	if p == 1 or p == 4:
		return False
	elif p == 2 or p == 3:
		return True
	else:
		for i in range(5):
			a = random.randint(2, p - 2)
			if pow(a, p - 1, p) != 1:
				return False
		return True
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes') if fermatPrime(N) else print('No')
	elif K == 2 and N % 2 == 0:
		print('Yes')
	elif K == 2 and N % 2 != 0:
		print('Yes') if fermatPrime(N - 2) else print('No')
	else:
		print('Yes')


import random

def fermatPrime(p):
	if p == 1 or p == 4:
		return False
	elif p == 2 or p == 3:
		return True
	else:
		for i in range(5):
			a = random.randint(2, p - 2)
			if pow(a, p - 1, p) != 1:
				return False
		return True
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if N < 2 * K:
		print('No')
	elif K == 1:
		print('Yes') if fermatPrime(N) else print('No')
	elif K == 2 and N % 2 == 0:
		print('Yes')
	elif K == 2 and N % 2 != 0:
		print('Yes') if fermatPrime(N - 2) else print('No')
	else:
		print('Yes')