Polycarp wants to buy exactly $n$ shovels. The shop sells packages with shovels. The store has $k$ types of packages: the package of the $i$-th type consists of exactly $i$ shovels ($1 \le i \le k$). The store has an infinite number of packages of each type.

Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $n$ shovels?

For example, if $n=8$ and $k=7$, then Polycarp will buy $2$ packages of $4$ shovels.

Help Polycarp find the minimum number of packages that he needs to buy, given that he:   will buy exactly $n$ shovels in total;  the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $1$ to $k$, inclusive. 


-----Input-----

The first line contains an integer $t$ ($1 \le t \le 100$) — the number of test cases in the input. Then, $t$ test cases follow, one per line.

Each test case consists of two positive integers $n$ ($1 \le n \le 10^9$) and $k$ ($1 \le k \le 10^9$) — the number of shovels and the number of types of packages.


-----Output-----

Print $t$ answers to the test cases. Each answer is a positive integer — the minimum number of packages.


-----Example-----
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733

Output
2
8
1
999999733
1



-----Note-----

The answer to the first test case was explained in the statement.

In the second test case, there is only one way to buy $8$ shovels — $8$ packages of one shovel.

In the third test case, you need to buy a $1$ package of $6$ shovels.

Source: codeforces | Difficulty: EASY
Tags: Number theory

Mathematics


Solutions:
import math
import bisect

def printDivisors(n, k, l):
	i = 1
	p = min(math.sqrt(n), k)
	while i <= p:
		if n % i == 0:
			if n / i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
for i in range(int(input())):
	(n, k) = map(int, input().split())
	nn = n
	l = []
	printDivisors(n, k, l)
	l.sort()
	c = bisect.bisect_right(l, k)
	if nn <= k:
		print(1)
		continue
	print(int(nn // l[c - 1]))


def N():
	return int(input())

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

def L():
	return list(NM())

def LN(n):
	return [N() for i in range(n)]

def LL(n):
	return [L() for i in range(n)]
t = N()

def f():
	(n, k) = NM()
	l = []
	for i in range(1, int(n ** 0.5) + 2):
		if n % i == 0:
			l.append(i)
			l.append(n // i)
	ans = n
	for i in l:
		if i <= k:
			ans = min(ans, n // i)
	print(ans)
for i in range(t):
	f()


import math
T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split(' '))
	if N <= K:
		res = 1
	else:
		num = min(int(math.sqrt(N)), K)
		res = N
		while num >= 1:
			if N % num == 0:
				t = N // num
				if t <= K:
					res = min(res, num)
				else:
					res = min(res, t)
			num -= 1
	print(res)


t = int(input())
for _ in range(t):
	(n, m1) = [int(i) for i in input().split()]
	f = -1
	if n == m1:
		print(1)
		continue
	elif n < m1:
		print(1)
		continue
	else:
		m = n
		n1 = int(n ** 0.5)
		for i in range(1, n1 + 1):
			if n % i == 0:
				if i <= m1:
					m = min(m, int(n / i))
				if int(n / i) <= m1:
					m = min(m, i)
		print(m)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		maxi = 1
		for i in range(1, int(math.sqrt(n)) + 1):
			if n % i == 0:
				if i <= k:
					if maxi < i:
						maxi = i
				if i != n // i:
					if n // i <= k:
						if maxi < n // i:
							maxi = n // i
		print(n // maxi)


def main():
	t = int(input())
	for i in range(t):
		(n, k) = map(int, input().split())
		faktori = []
		for d in range(1, int(n ** 0.5) + 1):
			if n % d == 0:
				faktori.append(d)
				faktori.append(n // d)
		faktori.sort(reverse=True)
		for j in faktori:
			if j <= k:
				print(n // j)
				break
main()


import sys
from bisect import bisect_left, bisect_right
from collections import deque
INF = 1 << 60

def make_divisors(n):
	(lower_divisors, upper_divisors) = ([], [])
	i = 1
	while i * i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n // i)
		i += 1
	return lower_divisors + upper_divisors[::-1]
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	d = make_divisors(n)
	i = bisect_right(d, k)
	ans = d[i - 1]
	print(n // ans)


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
import math

def solve(t):
	(n, k) = map(int, input().strip().split())
	if k >= n:
		return 1
	i = int(math.sqrt(n))
	min_val = float('inf')
	while i >= 1:
		if n % i == 0:
			if n // i <= k:
				min_val = min(min_val, i)
			elif i <= k:
				min_val = min(min_val, n // i)
		i -= 1
	return min_val

def main():
	tc = int(input().strip())
	for t in range(1, tc + 1):
		print(solve(t))
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()


t = int(input())
for t_ in range(t):
	(n, k) = map(int, input().split())
	factors = []
	if n <= k:
		print(1)
	else:
		sqroot = int(n ** 0.5 + 1)
		max = 0
		for i in range(2, sqroot):
			if n % i == 0:
				ni = n // i
				if ni <= k:
					max = ni
					break
				if i <= k:
					max = i if i > max else max
		if max == 0:
			print(n)
		else:
			print(n // max)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		r = 1
		p = min(k, int(pow(n, 0.5)) + 1)
		if n % 2 == 0:
			z = 2
			x = 1
		else:
			z = 3
			x = 2
		for j in range(z, p + 1, x):
			if n % j == 0:
				r = j
				if n // j <= k:
					r = n // j
					break
		print(n // r)


import math

def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	for case in range(int(input())):
		(n, k) = [int(x) for x in input().split()]
		max_factor = 1
		for i in range(1, int(math.sqrt(n)) + 1):
			if n % i == 0:
				a = n // i
				b = i
				if a <= k:
					max_factor = max(a, max_factor)
				if b <= k:
					max_factor = max(b, max_factor)
		print(n // max_factor)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ret = n
	i = 1
	while i ** 2 <= n:
		if n % i == 0 and i <= k:
			ret = min(ret, n / i)
		if n % i == 0 and n / i <= k:
			ret = min(ret, i)
		i += 1
	print(int(ret))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ans = 1
	for j in range(1, int(pow(n, 0.5)) + 1):
		if not n % j:
			if j <= k:
				ans = max(ans, j)
				if n <= k * j:
					ans = max(ans, n // j)
	print(n // ans)


import math

def solve(n, k):
	d = 1
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i > d and i <= k:
				d = i
			if n // i > d and n // i <= k:
				d = n // i
		if i > k:
			break
	return n // d
t = int(input())
while t != 0:
	t -= 1
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		print(solve(n, k))


t = int(input())
ans = []
for g in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		ans += [1]
	else:
		d = 1
		q = 1
		while d ** 2 <= n:
			if n % d == 0:
				if d <= k:
					q = d
					if n // d <= k:
						q = n // d
						break
				else:
					break
			d += 1
		ans += [n // q]
for i in ans:
	print(i)


def main():
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		return
	ans = n
	for i in range(1, int(n ** (1 / 2)) + 1):
		if not n % i:
			if n // i <= k:
				ans = i
				break
			elif i <= k:
				ans = min(ans, n // i)
			else:
				break
	print(ans)
for _ in range(int(input())):
	main()


import math
t = int(input())
for i in range(t):
	x = 0
	(n, k) = map(int, input().split())
	end = int(math.sqrt(n))
	if k >= n:
		y = 1
	else:
		for i in range(1, min(k, end) + 1):
			if n % i == 0:
				x = max(x, i)
				if int(n / x) <= k:
					x = max(x, int(n / x))
				y = int(n / x)
	print(y)


import math

def solve():
	ans = 10 ** 10
	value = math.ceil(math.sqrt(n))
	for i in range(1, value + 1):
		if n / i <= k and n % i == 0:
			ans = min(ans, i)
		if i <= k and n % i == 0:
			ans = min(ans, n // i)
	return ans
testcases = int(input())
for i in range(testcases):
	(n, k) = map(int, input().split())
	print(solve())


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		p = 1
		i = 2
		while i <= k and i <= math.sqrt(n):
			if n % i == 0:
				if n // i <= k:
					p = max(i, n // i, p)
				else:
					p = max(i, p)
			i = i + 1
		print(n // p)


import sys
import math
try:
	sys.stdin = open('Input.txt', 'r')
	sys.stdout = open('Output.txt', 'w')
except:
	pass
input = sys.stdin.readline
for testCases in range(int(input())):
	(n, k) = map(int, input().split())
	factors = []
	for i in range(1, math.ceil(n ** 0.5) + 1):
		if n % i == 0:
			factors.append(i)
			factors.append(n // i)
	factors.sort(reverse=True)
	for i in range(len(factors)):
		if factors[i] <= k:
			print(n // factors[i])
			break


import math as mt
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	val = int(mt.sqrt(n))
	ans = int(9000000000)
	for i in range(1, val + 1, 1):
		if n % i == 0:
			if n / i <= k:
				ans = min(ans, i)
			if i <= k:
				ans = min(ans, int(n / i))
	print(ans)


t = int(input())
for tt in range(t):
	(n, k) = [int(i) for i in input().split(' ')]
	ans = n
	for i in range(1, n + 1):
		if i * i > n:
			break
		if n % i == 0:
			if i <= k:
				ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
	print(ans)


import sys
import math
import collections

def set_debug(debug_mode=False):
	if debug_mode:
		fin = open('input.txt', 'r')
		sys.stdin = fin
t = int(input())
for ti in range(1, t + 1):
	(n, k) = list(map(int, input().split()))
	if k >= n:
		print(1)
		continue
	res = n
	for i in range(2, min(int(math.sqrt(n)) + 1, k + 1)):
		if n % i == 0:
			if n // i <= k:
				res = i
				break
			else:
				res = n // i
	print(res)


import math
t = int(input())
i = 0
while i < t:
	i += 1
	(n, k) = map(int, input().split())
	j = 1
	flag = 0
	temp = 1
	val = min(math.sqrt(n), k)
	while j <= val:
		if n % j == 0:
			if n / j <= k:
				flag = 1
				print(j)
				break
			else:
				temp = j
		j += 1
	if flag == 0:
		print(int(n / temp))


(z, zz, dgraphs) = (input, lambda : list(map(int, z().split())), {})
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	(a, b) = zz()
	if a <= b:
		print(1)
		continue
	if ceil(a / 2) <= b:
		t = ceil(a / 2)
	else:
		t = b
	p = 547548778787878788789789898989898989898989809
	x = ceil(a ** 0.5) + 1
	c = 0
	for i in range(x, 0, -1):
		if a % i == 0:
			j = a // i
			if j <= b:
				c = max(j, c)
			if i <= b:
				c = max(c, i)
	print(a // c)


from sys import stdin
input = stdin.readline
for Ti in range(int(input().strip())):
	(n, k) = [int(x) for x in input().strip().split()]
	i = 1
	a = float('inf')
	while i * i <= n and i <= k:
		(rem, div) = (n % i, n // i)
		if not rem:
			if div <= k:
				a = min(a, i)
			a = min(a, div)
		i += 1
	print(a)


import math

def printDivisors(n, k):
	ans = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				ans.append(i)
			else:
				ans.append(i)
				ans.append(n // i)
		i += 1
	ans.sort()
	for i in range(len(ans) - 1, -1, -1):
		if ans[i] <= k:
			break
	return ans[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
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	elif isPrime(n):
		print(n)
	else:
		x = printDivisors(n, k)
		print(int(n / int(x)))


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
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		i = 1
		ans = 9999999999999999
		while i * i <= n:
			if n % i == 0:
				if n // i <= k:
					ans = min(ans, i)
				if i <= k:
					ans = min(ans, n // i)
			i += 1
		print(ans)


import math
t = int(input())
for i in range(0, t):
	l = list(map(int, input().split()))
	res = l[0]
	for j in range(1, int(math.sqrt(l[0]) + 1)):
		if l[0] % j == 0:
			if l[0] / j <= l[1]:
				res = min(res, j)
			elif j <= l[1]:
				res = min(res, l[0] / j)
	print(int(res))


from math import sqrt

def solve(n, k):
	ans = n
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			if n // i <= k:
				ans = min(ans, i)
			if i <= k:
				ans = min(ans, n // i)
	return ans

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


cases = int(input())

def max_divisor(a, b):
	a_divisors = divisors(a)
	a_divisors = sorted(a_divisors)
	for x in range(len(a_divisors) - 1, -1, -1):
		if a_divisors[x] <= b:
			return a // a_divisors[x]
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])
	return list(set(divs))
for x in range(0, cases):
	(a, b) = [int(x) for x in input().split()]
	if a < b:
		print('1')
	elif a % b == 0:
		print(str(a // b))
	else:
		print(str(int(max_divisor(a, b))))


from collections import Counter
import string
import math
import sys

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))

def printDivisors(n):
	divisors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				divisors.append(i)
			else:
				divisors.extend((i, n // i))
		i = i + 1
	return divisors
for _ in range(vary(1)):
	(n, k) = vary(2)
	z = printDivisors(n)
	z.sort(reverse=True)
	for i in z:
		if i > k:
			continue
		else:
			print(n // i)
			break


import sys
import heapq

def main():
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, sys.stdin.readline().split())
		if a <= b:
			print(1)
			continue
		if b == 1:
			print(a)
			continue
		temp = 0
		for i in range(1, min(b + 1, int(a ** 0.5) + 1)):
			if a % i == 0:
				temp = max(temp, i)
				if a // i <= b:
					temp = max(temp, a // i)
		print(a // temp)
	return
main()


from math import sqrt, ceil
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	div = []
	for i in range(1, ceil(sqrt(n)) + 1):
		if n % i == 0:
			div.append(i)
			div.append(n // i)
	div.sort(reverse=True)
	for i in div:
		if i <= k:
			print(n // i)
			break


import sys
input = sys.stdin.readline
for t in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		ans = 1
	else:
		ans = n
		d = []
		for x in range(2, 1 + int(n ** 0.5)):
			if n % x == 0:
				if x > k:
					break
				else:
					d.append(x)
				y = n // x
				if y <= k:
					d.append(y)
		if d:
			w = max(d)
			ans = min(ans, n // w)
	print(ans)


from math import sqrt
text = [*open(0)]
for s in text[1:]:
	(n, k) = map(int, s.split())
	if n <= k:
		print(1)
	else:
		ans = 999999999999999
		i = 2
		for i in range(2, max(int(sqrt(k)), int(sqrt(n))) + 1):
			if n % i == 0:
				if n // i <= k:
					ans = min(ans, i)
				if i <= k:
					ans = min(ans, n // i)
		if ans != 999999999999999:
			print(ans)
		else:
			print(n)


import math
q = int(input())
while q:
	(n, k) = map(int, input().split())
	minPacks = n
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0 and i <= k:
			minPacks = min(minPacks, n // i)
			if n // i <= k:
				minPacks = min(minPacks, i)
	print(minPacks)
	q -= 1


import math

def printDivisors(n, k):
	i = 2
	mx = n
	while i <= math.sqrt(n):
		if n % i == 0:
			c = n // i
			if i <= k:
				mx = min(mx, c)
			if c <= k:
				mx = min(mx, i)
		i = i + 1
	return mx
for lo in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	print(printDivisors(n, k))


from math import ceil, sqrt

def solution():
	(n, k) = map(lambda x: int(x), input().split())
	max_shovel_cnt = ceil(sqrt(n))
	if k >= n:
		print(1)
		return
	if k == 1:
		print(n)
		return
	answer = n
	for i in range(2, max_shovel_cnt + 1):
		if n % i == 0:
			if n // i <= k:
				answer = min(answer, i)
			if i <= k:
				answer = min(answer, n // i)
	print(answer)
t = int(input())
for _ in range(t):
	solution()


y = int(input())
for i in range(y):
	(n, k) = map(int, input().split())
	cost = n
	flag = False
	if k >= n:
		print(1)
		flag = False
	else:
		for t in range(2, int(n ** 0.5) + 2):
			if n % t == 0 and k >= n // t:
				print(t)
				flag = True
				break
			elif n % t == 0 and k >= t:
				cost = n // t
		if not flag:
			print(cost)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n
	i = 1
	while i * i <= n and i <= k:
		if n % i == 0:
			if n // i <= k:
				ans = i
				break
			ans = min(ans, n // i)
		i += 1
	print(ans)


from sys import stdin
import math
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, stdin.readline().rstrip().split(' ')))
	if k >= n:
		print(1)
		continue
	answer = 1
	for i in range(2, min(k, math.ceil(math.sqrt(n))) + 1):
		if n % i == 0:
			answer = i
			if n / i <= k:
				print(i)
				break
	else:
		print(n // answer)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	n2 = int(n ** 0.5 + 1)
	res = n
	for i in range(1, n2):
		if n % i == 0:
			j = n // i
			if j <= k:
				res = min(res, i)
			if i <= k:
				res = min(res, j)
	print(res)


import sys, math, io, os, time, itertools, collections
mod = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(10000)
i = sys.stdin.readline
p = sys.stdout.write
global start, end

def div(n):
	l = deque()
	p = int(math.sqrt(n))
	for k in range(p, 0, -1):
		if n % k == 0:
			if n // k == k:
				l.append(k)
			else:
				l.append(n // k)
				l.appendleft(k)
	return reversed(l)

def main():
	(n, K) = [int(k) for k in i().split()]
	for el in div(n):
		if el <= K:
			p(str(n // el) + '\n')
			break
t = 1
t = int(i())
start = time.perf_counter()
for _ in range(t):
	main()
end = time.perf_counter()


import math
t = int(input())
for i in range(t):
	(n, k) = [int(n) for n in input().split()]
	p = k
	ans = 1
	if k >= int(math.sqrt(n)):
		k = int(math.sqrt(n)) + 1
	for j in range(1, k + 1):
		if n % j == 0:
			ans = max(ans, j)
			if n // j <= p:
				ans = max(n // j, ans)
	print(n // ans)


import math
number = int(input())
for iTask in range(number):
	inputs = input()
	(n, k) = list(map(int, inputs.split(' ')))
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	elif n % k == 0:
		print(int(n / k))
	else:
		sizeLim = min(k, int(math.sqrt(n + 1)))
		size = 2
		found = False
		savedSize = 1
		while size <= sizeLim:
			if n % size == 0:
				savedSize = size
				if n / size < k:
					found = True
					print(size)
					break
			size += 1
		if not found:
			print(int(n / savedSize))


def solve(n, k):

	def is_prime(num):
		if num == 1:
			return False
		i = 2
		while i * i <= num:
			if num % i == 0:
				return False
			i += 1
		return True

	def max_div(num, k):
		divisors = [1, num]
		i = 2
		while i * i <= num:
			if num % i == 0:
				divisors.append(i)
				divisors.append(num // i)
			i += 1
		divisors.sort()
		maxdiv = 1
		for d in divisors:
			if d <= k:
				maxdiv = max(maxdiv, d)
		return num // maxdiv
	if n > k:
		if is_prime(n):
			return n
		else:
			return max_div(n, k)
	return 1
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	result = solve(n, k)
	print(result)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	i = 1
	max1 = 1
	while i * i <= n and i <= k:
		if n % i == 0:
			if n / i <= k:
				max1 = max(max1, n / i)
			else:
				max1 = max(max1, i)
		i += 1
	print(int(n / max1))


from math import sqrt

def gf(n, k):
	hi = 1
	for i in range(1, min(k, int(sqrt(n))) + 1):
		if n % i == 0:
			if n // i <= k:
				hi = max(hi, n // i)
			else:
				hi = max(hi, i)
	return hi
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(n // gf(n, k))


import math

def Prime(n, k):
	global ys
	ys = [1]
	i = 2
	f = False
	while i * i <= n:
		if n % i == 0:
			ys.append(i)
			ys.append(n // i)
			f = True
		i = i + 1
	return f

def inp():
	return map(int, input().split())
for _ in range(int(input())):
	(n, k) = inp()
	if k >= n:
		print(1)
		continue
	elif k == 1:
		print(n)
		continue
	elif Prime(n, k) == False:
		print(n)
	else:
		ys.sort(reverse=True)
		for x in ys:
			if x <= k:
				print(n // x)
				break


def shovels(n, k):
	array = []
	c = 0
	if k == 1:
		return n
	elif n <= k:
		return 1
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				if n // i <= k:
					return i
				else:
					c += 1
					array.append(i)
		for i in range(c):
			a = array[c - 1 - i]
			if a <= k:
				return n // a
		else:
			return n
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	print(shovels(n, k))


import sys
t = int(input())
for tc in range(t):
	s = list(map(int, input().split()))
	(n, k) = (s[0], s[1])
	ans = 1
	p = int(pow(n, 0.5))
	for i in range(1, p + 1):
		if n % i == 0:
			if i <= k:
				ans = max(ans, i)
			if n // i <= k:
				ans = max(ans, n // i)
	print(n // ans)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	i = 1
	arr = []
	while i <= math.sqrt(n):
		if n % i == 0:
			arr.extend([i, n // i])
		i += 1
	ans = 1
	for x in arr:
		if x <= k:
			ans = max(x, ans)
	print(n // ans)


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

def main():
	t = int(input())
	for i in range(t):
		(n, k) = list(map(int, input().split()))
		ans = n
		v = int(math.sqrt(n))
		if n <= k:
			print(1)
			continue
		for j in range(1, v + 5):
			if n % j == 0 and j <= k:
				ans = min(ans, n // j)
			other = n // j
			if n % other == 0 and other <= k:
				ans = min(ans, n // other)
		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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for q in range(t):
	ch = input()
	L = [int(i) for i in ch.split()]
	(a, k) = (L[0], L[1])
	t = False
	x = int(a ** 0.5)
	L2 = []
	for j in range(1, x + 2):
		if a % j == 0:
			if j <= k:
				L2.append(a // j)
			if a // j <= k:
				L2.append(j)
	print(min(L2))


import math
a = int(input())
for s in range(a):
	b = [int(x) for x in input().split()]
	wurzel = math.ceil(math.sqrt(b[0]))
	x = 1
	flag = 0
	while x <= wurzel:
		if b[0] % x == 0:
			if b[0] // x <= b[1]:
				print(x)
				break
			elif x <= b[1]:
				flag = b[0] // x
		x += 1
	else:
		if flag == 0:
			print(b[0])
		else:
			print(flag)


def sol():
	(x, y) = map(int, input().split())
	res = 0
	for n in range(1, min(y, int(x ** 0.5)) + 1):
		if x % n == 0:
			res = max(res, n)
			if x / n <= y:
				res = max(res, x // n)
	print(x // res)
for n in range(int(input())):
	sol()


import sys
import math
file_name = ''
if file_name:
	f = open(file_name, 'r')
else:
	f = sys.stdin
line = f.readline()
q = int(line)
for _ in range(q):
	line = f.readline()
	(n, k) = [int(x) for x in line.split()]
	answer = 1
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if answer < n / i <= k:
				answer = n / i
			if answer < i <= k:
				answer = i
	print(int(n / answer))


from math import sqrt, ceil

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

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

def read_int_array():
	return [int(_) for _ in read_string_array()]

def read_line():
	return input()

def factors(n):
	f = []
	for i in range(1, ceil(sqrt(n + 1))):
		if n % i == 0:
			f.append(i)
			f.append(n // i)
	return f

def solve(n, k):
	pack_sizes = [_ for _ in factors(n) if _ <= k]
	min_packs = float('inf')
	for d in pack_sizes:
		min_packs = min(min_packs, n // d)
	return min_packs
T = read_int()
for _ in range(T):
	(N, K) = read_int_array()
	print(solve(N, K))


import sys
t = []
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 generateDivisors(curIndex, curDivisor, arr):
	if curIndex == len(arr):
		global t
		t.append(curDivisor)
		return
	for i in range(arr[curIndex][0] + 1):
		generateDivisors(curIndex + 1, curDivisor, arr)
		curDivisor *= arr[curIndex][1]

def findDivisors(n):
	arr = []
	i = 0
	while i < len(primes) and primes[i] <= n:
		if n % primes[i] == 0:
			count = 0
			while n % primes[i] == 0:
				n //= primes[i]
				count += 1
			arr.append([count, primes[i]])
		i += 1
	if n > 1:
		arr.append([1, n])
	curIndex = 0
	curDivisor = 1
	generateDivisors(curIndex, curDivisor, arr)
q = int(input())
for i in range(q):
	(n, k) = [int(i) for i in sys.stdin.readline().split()]
	m = n
	if n <= k:
		print(1)
	else:
		t = []
		findDivisors(n)
		t.sort()
		j = 0
		while j < len(t) and k >= t[j]:
			j += 1
		if j == 0:
			print(m)
		else:
			print(m // t[j - 1])


import math

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):
	if n <= k:
		res = 1
	else:
		my_list = []
		new = []
		i = 1
		while i <= math.sqrt(n):
			if n % i == 0:
				if n / i == i:
					my_list.append(i)
				else:
					my_list.append(i)
					my_list.append(n // i)
			i = i + 1
		for i in range(len(my_list)):
			if my_list[i] <= k:
				new.append(my_list[i])
		res = n // max(new)
	print(res)
n = inp()
for i in range(n):
	my_list1 = inlt()
	a = my_list1[0]
	b = my_list1[1]
	solve(a, b)


import sys
from math import sqrt
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
mod = 1000000007

def div(n):
	res = []
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if n // i == i:
				res.append(i)
			else:
				res.append(n // i)
				res.append(i)
	return res

def solve():
	t = int(sys.stdin.readline())
	for _ in range(t):
		(n, k) = map(int, sys.stdin.readline().split())
		ans = sorted(div(n))
		nn = None
		for i in ans:
			if i <= k:
				nn = i
		print(n // nn)
solve()


import math
inf = 10 ** 18

def main():
	for tc in range(int(input())):
		(n, k) = map(int, input().split())
		if k >= n:
			print(1)
			continue
		sq = int(math.sqrt(n))
		mx = -inf
		for i in range(1, sq + 1, 1):
			if n % i == 0:
				if i <= k:
					mx = max(mx, i)
				if n // i <= k:
					mx = max(mx, n // i)
		print(n // mx)
main()


import math
n = int(input())
for i in range(0, n):
	(a, b) = map(int, input().split())
	if a <= b:
		print(1)
	else:
		ans = a
		c = int(math.sqrt(a))
		for j in range(1, c + 1):
			if a % j == 0:
				if j <= b:
					ans = min(ans, a // j)
				if a // j <= b:
					ans = min(ans, j)
		print(ans)


from bisect import bisect_right

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 _ in range(t):
	(n, k) = map(int, input().split())
	d = make_divisors(n)
	idx = bisect_right(d, k)
	print(n // d[idx - 1])


import math
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 _ in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	elif k == 1:
		print(n)
	else:
		a = list(factors(n))
		c = 0
		a.sort()
		for i in range(len(a)):
			if a[i] <= k:
				c = max(c, a[i])
		print(n // c)


def div_lis(x):
	(div_l, div_r) = ([], [])
	for i in range(1, int(x ** 0.5) + 1):
		if x % i != 0:
			continue
		div_l.append(i)
		if i != x // i:
			div_r.append(x // i)
	div = div_l + div_r[::-1]
	return div
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
		continue
	div = div_lis(n)
	for d in div:
		if n // d <= k:
			print(d)
			break


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = []
	s = int(n ** (1 / 2)) + 1
	res = 2 << 32 - 1
	for i in range(1, s + 1):
		if n % i == 0:
			if i <= k:
				res = min(res, n // i)
			if n / i <= k:
				res = min(res, i)
	print(res)


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	else:
		ans = n
		for _ in range(min(int(math.sqrt(n)), k), 1, -1):
			if not n % _:
				if n // _ <= k:
					ans = min(ans, _)
				if _ <= k:
					ans = min(ans, n // _)
		print(ans)


from bisect import bisect_right as br
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	dv = [i for i in range(1, int(n ** 0.5) + 1) if n % i == 0]
	x = len(dv)
	for i in range(x):
		dv.append(n // dv[i])
	dv.sort()
	print(n // dv[br(dv, k) - 1])


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ans = n
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i <= k:
				ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = []
	if n <= k:
		print('1')
	elif n > k and n % k == 0:
		print(n // k)
	else:
		for j in range(int(n ** 0.5), 0, -1):
			if n % j == 0:
				if n // j == j:
					arr.append(j)
				else:
					arr.extend([j, n // j])
		arr.sort(reverse=True)
		for j in arr:
			if j <= k and n % j == 0:
				print(n // j)
				break


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n
	i = 1
	while i * i <= n:
		if n % i == 0:
			if i <= k:
				ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
		i += 1
	print(ans)


def shovels(n, k):
	ans = n
	for j in range(1, int(n ** 0.5) + 1):
		if n % j == 0:
			if j <= k:
				ans = min(ans, n // j)
			if n // j <= k:
				ans = min(ans, j)
	return ans
test = int(input())
for i in range(test):
	(n, k) = map(int, input().split())
	print(shovels(n, k))


import math
import bisect

def divisors(n):
	divs = [1]
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			divs.extend([i, int(n / i)])
	divs.extend([n])
	return list(set(divs))
for ii in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		p = divisors(n)
		p.sort()
		q = bisect.bisect_left(p, k, lo=0, hi=len(p))
		if p[q] == k:
			print(int(n / p[q]))
		else:
			print(int(n / p[q - 1]))


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)))
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		ans = 1
	elif k == 1:
		ans = n
	else:
		ans = 10 ** 9
		l = list(factors(n))
		l.sort()
		for i in l:
			if i > k:
				break
			if n % i == 0:
				ans = min(ans, n // i)
	print(ans)


import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
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')

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 SieveOfEratosthenes(n):
	prime = []
	primes = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if primes[p] == True:
			prime.append(p)
			for i in range(p * p, n + 1, p):
				primes[i] = False
		p += 1
	return prime
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	fac = set()
	for i in range(1, int(math.sqrt(n)) + 2):
		if n % i == 0 and i <= k:
			fac.add(i)
			if n // i <= k:
				fac.add(n // i)
	fac = list(fac)
	fac.sort(reverse=True)
	print(n // fac[0])


import math

def factors(n, k):
	biggestFactor = -1
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			s = n // i
			if i > biggestFactor and i <= k:
				biggestFactor = i
			if s > biggestFactor and s <= k:
				biggestFactor = s
	return biggestFactor
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
		continue
	f = factors(n, k)
	if f == -1:
		print(n)
	else:
		print(n // f)


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(reverse=True)
	return divisors
T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	D = make_divisors(N)
	for d in D:
		if d <= K:
			print(N // d)
			break


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	maxx = -1
	hg = min(int(math.sqrt(n)), k)
	for i in range(1, hg + 1):
		if n % i == 0:
			if i > maxx:
				maxx = i
			if n // i <= k and n // i > maxx:
				maxx = n // i
	print(n // maxx)


import math
from sys import *
t = int(stdin.readline())
while t > 0:
	(n, k) = map(int, stdin.readline().split())
	ans = n
	for j in range(1, int(math.sqrt(n)) + 1):
		if n % j == 0:
			if j <= k:
				ans = min(ans, n // j)
			if n // j <= k:
				ans = min(ans, j)
	print(ans)
	t -= 1


import math

def find_divisors(n):
	divisors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.append(i)
				divisors.append(n / i)
		i = i + 1
	return divisors

def check(a, b):
	divisors = find_divisors(a)
	divisors.sort()
	for i in range(len(divisors)):
		if divisors[len(divisors) - i - 1] <= b:
			return int(divisors[len(divisors) - i - 1])
		i += 1

def main():
	count = input()
	a = [[] for i in range(int(count))]
	for i in range(len(a)):
		inputstr = input()
		a[i] = inputstr.split()
		a[i] = list(map(int, a[i]))
		ans = check(a[i][0], a[i][1])
		print(int(a[i][0] / ans))
main()


def get_max_factor(x, k):
	r = []
	for i in range(1, x + 1):
		if i * i > x:
			break
		if x % i == 0:
			r.append(i)
			r.append(x // i)
	ret = 1
	for e in r:
		if e <= k:
			ret = max(ret, e)
	return ret
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	cnt = 0
	if n <= k:
		print(1)
		continue
	p = get_max_factor(n, k)
	cnt += n // p
	print(cnt)


import sys
import bisect
from functools import reduce

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 shovels(n, k):
	if n % k == 0:
		return int(n / k)
	li = factors(n)
	p = bisect.bisect(li, k)
	return n // li[p - 1]
t = int(sys.stdin.readline())
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	print(shovels(n, k))


import math
for t in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	elif n % k == 0:
		print(n // k)
	else:
		i = 1
		m = 1
		while i <= math.sqrt(n):
			if n % i == 0:
				if n / i == i:
					if i > k:
						break
					if m < i:
						m = i
				else:
					temp2 = min(i, n / i)
					if temp2 > k:
						break
					temp = max(i, n / i)
					if temp < k:
						if m < temp:
							m = temp
					elif m < temp2:
						m = temp2
			i += 1
		print(int(n // m))


for t in range(int(input())):
	(n, k) = [int(c) for c in input().split()]
	i = ans = 1
	a = []
	while i < int(n ** 0.5) + 2:
		if n % i == 0 and i <= k:
			a.append(i)
			a.append(n // i)
		i += 1
	a.sort()
	for i in a:
		if i <= k:
			ans = max(ans, i)
		else:
			break
	print(n // ans)


def func(n, k):
	m = 0
	if n == k:
		print(1)
	else:
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0 and i <= k and (i > m):
				m = i
				if n // i != i and n // i <= k and (n // i > m):
					m = n // i
		print(n // m)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	func(n, k)


import sys
import os
import heapq
import math
try:
	path = './file/input.txt'
	if os.path.exists(path):
		sys.stdin = open(path, 'r')
except:
	pass
t = int(input())

def printd(value):
	pass
for _ in range(t):
	arr = list(map(int, input().split(' ')))
	(n, k) = (arr[0], arr[1])
	result = n
	end = min(k, int(math.sqrt(n)) + 1)
	for i in range(1, end + 1):
		if n % i == 0:
			number = int(n / i)
			if number <= k:
				result = min(result, i)
			if i <= k:
				result = min(number, result)
	print(result)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	j = 1
	for i in range(1, int(math.sqrt(n) + 1)):
		if i <= k:
			if n % i == 0:
				if n // i <= k:
					j = max(n // i, j)
				j = max(j, i)
	print(int(n / j))


import math
T = int(input())

def ans(n, k):
	for f in range(1, math.ceil(math.sqrt(n))):
		if n % f > 0:
			continue
		cf = n // f
		if cf <= k:
			return f
	for f in range(math.ceil(math.sqrt(n)), 0, -1):
		if n % f > 0:
			continue
		if f <= k:
			return n // f
	return '?'
for t in range(T):
	(n, k) = input().split(' ')
	(n, k) = (int(n), int(k))
	print(ans(n, k))


t = int(input())

def dividers(N):
	D = [1]
	d = 2
	while d * d <= N:
		if N % d == 0:
			D = D + [d]
			d_new = N // d
			if d_new != d:
				D = D + [d_new]
		d += 1
	D += [N]
	D.sort()
	return D
for i in range(t):
	(n, k) = map(int, input().split())
	for i in dividers(n)[::-1]:
		if i <= k:
			print(n // i)
			break


import math

def printDivisors(n):
	x = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n == i * i:
				x.append(i)
			else:
				x.append(i)
				x.append(n // i)
		i = i + 1
	return x
for i in range(int(input())):
	nk = list(map(int, input().split()))
	n = nk[0]
	k = nk[1]
	x = printDivisors(n)
	y = []
	for a in x:
		if a <= k:
			y.append(a)
	print(n // max(y))


t = int(input())
import math

def factors(n, k):
	results = set()
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0 and i <= k:
			results.add(i)
			last = int(n / i)
			if last <= k:
				results.add(int(n / i))
	return results
for test in range(t):
	(n, k) = [int(x) for x in input().split()]
	high = 1
	if n <= k:
		print(1)
		continue
	ans = list(factors(n, k))
	ans.sort()
	print(n // ans[-1])


import math

def factors(n):
	return set((factor for i in range(1, int(n ** 0.5) + 1) if n % i == 0 for factor in (i, n // i)))
t = int(input())
while t != 0:
	(n, k) = map(int, input().strip().split())
	x = factors(n)
	maxFactor = -math.inf
	minpackages = math.inf
	x = sorted(x)
	for i in x:
		if i > k:
			break
		if i > maxFactor:
			maxFactor = i
			minpackages = n // i
	print(minpackages)
	t -= 1


import math
t = int(input())
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	divisors = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			divisors.append(i)
			divisors.append(n // i)
	divisors.sort(reverse=True)
	for i in divisors:
		if i <= k:
			print(n // i)
			break


import math
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)))
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(factors(n))
	print(n // sorted(filter(lambda x: x <= k, l), reverse=True)[0])


import sys, math, os
from io import BytesIO, IOBase
from collections import defaultdict as dd, deque, Counter

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

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1000000000.0) + 7

def main():
	for t in range(int(data())):
		(n, k) = mdata()
		m = INF
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				if i <= k:
					m = min(m, n // i)
				if n // i <= k:
					m = min(m, i)
					break
		out(m)
main()


def divisor(n):
	l = set()
	for i in range(1, int(n ** 0.5) + 1):
		if n % i != 0:
			continue
		(x, y) = (i, n // i)
		l.add(x)
		if x != y:
			l.add(y)
	return l
t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	l = list(divisor(n))
	l.sort()
	for j in range(len(l) - 1, -1, -1):
		if l[j] <= k:
			print(n // l[j])
			break


t = int(input())
for T in range(t):
	(n, k) = [int(x) for x in input().split()]
	ans = n
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i <= k:
				ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
	print(ans)


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):
	(n, k) = map(int, input().split())
	minsofar = n
	for s in range(1, math.ceil(math.sqrt(n)) + 1):
		if n % s == 0:
			maxy = max(s, n // s)
			miny = min(s, n // s)
			if maxy <= k and n // maxy < minsofar:
				minsofar = n // maxy
			elif miny <= k and n // miny < minsofar:
				minsofar = n // miny
	print(minsofar)


import sys
input = lambda : sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline

def I():
	return list(map(int, inp().split()))
from math import sqrt
for _ in range(I()[0]):
	(n, k) = I()
	a = []
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			a.append(i)
			a.append(n // i)
	a.sort(reverse=True)
	for i in a:
		if i <= k:
			print(n // i)
			break


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	fact = set()
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			fact.add(i)
			fact.add(n // i)
	fact = sorted(fact, reverse=True)
	for i in fact:
		if i > k:
			continue
		print(n // i)
		break


import math
T = int(input())
for _ in range(T):
	(n, k) = list(map(int, input().split()))
	divs = set()
	for d in range(1, int(math.sqrt(n)) + 2):
		if n % d == 0:
			divs.add(d)
			divs.add(n // d)
	ans = 10 ** 10
	for d in divs:
		if d > k:
			continue
		else:
			ans = min(ans, n // d)
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		i = 1
	else:
		i = 2
	d = 1
	found = False
	while i * i <= n and i <= k:
		if n % i == 0:
			d = max(d, i)
			if n // i <= k:
				d = max(d, n // i)
		i += 1
	print(n // d)


t = int(input())
for testIndex in range(t):
	(n, k) = map(int, input().split())
	maxDiv = 1
	i = 1
	while i * i <= n and i <= k:
		if n % i == 0:
			maxDiv = max(i, maxDiv)
			if n // i <= k:
				maxDiv = max(n // i, maxDiv)
		i += 1
	print(n // maxDiv)


import bisect
t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	k = int(l[1])
	lfi = []
	i = 1
	maxa = 1
	while i * i <= n:
		if n % i == 0:
			lfi.append(i)
			if i > maxa and i <= k:
				maxa = i
			if i != n // i:
				lfi.append(n // i)
				if n // i > maxa and n // i <= k:
					maxa = n // i
		i += 1
	print(n // maxa)


from sys import stdin, stdout
input = stdin.readline

def print(x):
	stdout.write(str(x) + '\n')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 10 ** 9 + 1
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i <= k:
				ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
	print(ans)


import os
import sys
import io
import math
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for t in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		root = math.ceil(math.sqrt(n))
		answer = n
		i = 2
		m = 1
		while i <= root and i <= k:
			if n % i == 0:
				if n // i <= k:
					m = max(m, n // i)
				else:
					m = max(m, i)
			i += 1
		print(n // m)


from sys import stdin, exit, setrecursionlimit
from collections import deque
from heapq import *
from math import gcd, sqrt
from math import ceil, log2
setrecursionlimit(10000000)
from collections import deque
input = stdin.readline
lmi = lambda : list(map(int, input().split()))
mi = lambda : map(int, input().split())
si = lambda : input().strip('\n')
ssi = lambda : input().strip('\n').split()
for _ in range(int(input())):
	(n, k) = mi()
	ans = float('inf')
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if i <= k:
				ans = min(n // i, ans)
			if n // i <= k:
				ans = min(n // (n // i), ans)
	print(ans)


import math
t = int(input())
res = []

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
for i in range(t):
	(n, k) = (int(n) for n in input().split())
	maxD = 1
	for d in divisorGenerator(n):
		if d <= k:
			maxD = d
	res.append(int(n / maxD))
for r in res:
	print(r)


q = int(input())
while q:
	q -= 1
	(n, k) = input().split(' ')
	(n, k) = (int(n), int(k))
	an = n
	for i in range(1, n):
		if i * i > n:
			break
		if n % i == 0:
			if i <= k:
				an = min(an, n / i)
			if n / i <= k:
				an = min(an, i)
	print(int(an))


import math

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


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ans = 1
	for i in range(1, int(n ** 0.5) + 1):
		if i > k:
			break
		if n % i == 0:
			ans = max(ans, i)
			if n // i <= k:
				ans = max(ans, n // i)
	print(n // ans)


from math import sqrt, floor

def calc(n, k):
	curr = 0
	lim = min(floor(sqrt(n)) + 1, k)
	for i in range(1, lim + 1):
		if n % i == 0:
			if i > curr:
				curr = i
			if n // i <= k and n // i > curr:
				curr = n // i
	return n // curr
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	print(calc(n, k))


for s in [*open(0)][1:]:
	(n, k) = map(int, s.split())
	i = 1
	x = n
	while i * i <= n and i <= k:
		if n % i == 0:
			if n // i <= k:
				x = i
				break
			x = min(x, n // i)
		i += 1
	print(x)


import math

def Ok(n, k):
	s = []
	l = []
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n / i == i:
				s.append(i)
			else:
				l.append(n // i)
				s.append(i)
	for j in l:
		if k >= j:
			return n // j
	s.reverse()
	for j in s:
		if k >= j:
			return n // j
	return 1
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(Ok(n, k))


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
import re

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

def printDivisors(n):
	divisors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.append(i)
				divisors.append(n / i)
		i = i + 1
	return divisors
t = INT()
while t != 0:
	(n, k) = MAP()
	if k >= n:
		print(1)
	else:
		factors = printDivisors(n)
		factors = list(factors)
		factors.sort()
		l = 0
		r = len(factors) - 1
		ans = -1
		while l < r:
			mid = (l + r) // 2
			if factors[mid] > k:
				r = mid
			else:
				ans = factors[mid]
				l = mid + 1
		print(int(n // ans))
	t -= 1


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


from __future__ import division, print_function
import itertools
import sys
import os
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def is_it_local():
	script_dir = str(os.getcwd()).split('/')
	username = 'dipta007'
	return username in script_dir

def READ(fileName):
	if is_it_local():
		sys.stdin = open(f'./{fileName}', 'r')
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')
if not is_it_local():
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')

def input1(type=int):
	return type(input())

def input2(type=int):
	[a, b] = list(map(type, input().split()))
	return (a, b)

def input3(type=int):
	[a, b, c] = list(map(type, input().split()))
	return (a, b, c)

def input_array(type=int):
	return list(map(type, input().split()))

def input_string():
	s = input()
	return list(s)
import math

def get_result(n, k):
	sq = int(min(math.sqrt(n), k))
	res = n
	for i in range(1, sq + 1):
		if n % i == 0:
			d1 = i
			d2 = n / i
			if d1 <= k:
				res = min(res, n / d1)
			if d2 <= k:
				res = min(res, n / d2)
	return int(res)

def main():
	t = input1()
	for ci in range(t):
		(n, k) = input2()
		print(get_result(n, k))
	pass
READ('in.txt')
main()


import math

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

def fctrlist(n):
	L = []
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			if n // i == i:
				L.append(i)
			else:
				L.append(n // i)
				L.append(i)
	return L
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		print(n)
		continue
	if n <= k:
		print(1)
		continue
	if checkprime(n):
		print(n)
		continue
	A = fctrlist(n)
	A.sort()
	i = 0
	d = 1
	while i < len(A):
		if n // A[i] <= k:
			d = n // A[i]
			break
		else:
			i += 1
	print(int(n // d))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	val = 1
	i = 1
	while i <= n ** 0.5:
		if n % i == 0 and i <= k:
			val = max(val, i)
			if n // i <= k:
				val = max(val, n // i)
		i += 1
	print(n // val)


import math
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if b >= a:
		print('1')
	elif a % b == 0:
		print(a // b)
	else:
		k = 0
		lis = []
		for j in range(int(math.sqrt(a)), 0, -1):
			if a % j == 0:
				lis.append(j)
				lis.append(a // j)
		lis = sorted(lis, reverse=True)
		for i in lis:
			if i <= b:
				print(a // i)
				break


from math import sqrt

def g(n, k):
	ans = n
	for i in range(1, 1 + int(sqrt(n))):
		if n % i == 0:
			if n // i <= k:
				ans = min(ans, i)
			if i <= k:
				ans = min(ans, n // i)
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(g(n, k))


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

def divs(n):
	i = 1
	div = set()
	while i * i <= n:
		if n % i == 0:
			div.add(i)
			div.add(n // i)
		i += 1
	return sorted(list(div))
from bisect import bisect_right as bs
for _ in range(inp()):
	(n, k) = ip()
	if n <= k:
		print(1)
		continue
	d = divs(n)
	ind = bs(d, k) - 1
	print(n // d[ind])


import math

def divisors(n):
	i = 1
	arr = []
	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 += 1
	return arr
t = int(input())
for i in range(t):
	nk = list(map(int, input().split()))
	n = nk[0]
	k = nk[1]
	if k >= n:
		print(1)
	else:
		arr = divisors(n)
		arr.sort()
		res = 1
		for i in range(len(arr) - 1):
			if arr[i] <= k and arr[i + 1] > k:
				res = arr[i]
				break
		print(n // res)


from math import sqrt, ceil
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)))

def isprime(n):
	if n <= 1:
		return 0
	if n <= 3:
		return 1
	if n % 2 == 0 or n % 3 == 0:
		return 0
	for i in range(5, int(sqrt(n)) + 1):
		if n % i == 0 or n % (i + 2) == 0:
			return 0
	return 1
n = int(input())
for _ in range(n):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	elif isprime(n):
		print(n)
	else:
		m = sorted(list(factors(n)))[::-1]
		for i in range(len(m)):
			if m[i] <= k:
				break
		print(n // m[i])


import sys
import math
input = sys.stdin.readline

def check_prime(n, k):
	maxi = 0
	gFlag = False
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n // i > maxi and n // i <= k:
				maxi = n // i
				gFlag = True
			elif i > maxi and i <= k:
				maxi = i
				gFlag = True
	return (False, -1) if not gFlag else (True, maxi)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	result = n
	if n <= k:
		print(1)
		continue
	elif k == 1:
		print(n)
		continue
	(truthVal, maxi) = check_prime(n, k)
	if truthVal:
		result = n // maxi
	print(result)


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())
	l = make_divisors(n)
	if n == 1:
		print(1)
		continue
	ans = l[-1]
	for j in range(1, len(l)):
		if l[j] > k:
			ans = l[j - 1]
			break
	print(n // ans)


from math import sqrt
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	fans = 1e+20
	for i in range(1, int(sqrt(n) + 1)):
		if n % i != 0:
			continue
		j = n // i
		if j <= k:
			fans = min(i, fans)
		if i <= k:
			fans = min(j, fans)
	print(fans)


t = int(input())
for i in range(t):
	(a, s) = map(int, input().split())
	dd = []
	i = 1
	while i * i <= a:
		if a % i == 0:
			dd.append(i)
			if i != a // i:
				dd.append(a // i)
		i += 1
	u = 0
	for o in dd:
		if o <= s:
			u = max(u, o)
	print(a // u)


from math import sqrt
for case in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	ans = n
	if k == 1:
		ans = n
	elif k >= n:
		ans = 1
	else:
		for i in range(1, n + 1):
			if i * i > n:
				break
			if n % i == 0:
				if i <= k:
					ans = min(ans, n // i)
				if n // i <= k:
					ans = min(ans, i)
	print(ans)


import sys
input = sys.stdin.readline
import math
Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]
for (n, k) in Query:
	ans = 10 ** 18
	for a in range(1, int(math.sqrt(n) + 2)):
		if n % a == 0:
			if n // a <= k:
				ans = min(ans, a)
			if a <= k:
				ans = min(ans, n // a)
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	if n <= k:
		print(1)
	else:
		i = 1
		ans = n
		x = min(int(n ** 0.5), k)
		while i <= x:
			if n % i == 0:
				if n // i <= k:
					ans = min(ans, i)
				else:
					ans = min(ans, n // i)
			i += 1
		print(ans)


import math

def divisors(n):
	i = 1
	div = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				div.append(i)
			else:
				div.append(i)
				div.append(n // i)
		i += 1
	return div
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		div = divisors(n)
		div.sort(reverse=True)
		for i in div:
			if i <= k:
				print(n // i)
				break


import math

def polycarpo(a, b):
	if a <= b:
		print(1)
	else:
		k = 0
		div = 1
		divisori = []
		while div <= int(math.sqrt(a) + 1):
			if a % div == 0 and div <= b:
				divisori.append(div)
			div += 1
		for i in range(len(divisori)):
			divisori.append(int(a / divisori[i]))
		divisori.sort()
		for i in range(len(divisori)):
			if a / divisori[i] <= b:
				print(divisori[i])
				return
T = int(input())
for k in range(T):
	(n, k) = [int(x) for x in input().split()]
	polycarpo(n, k)


import sys, math
input = lambda : sys.stdin.readline().strip()
inp = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	(n, k) = inp()
	if n <= k:
		print(1)
		continue
	lol = math.ceil(math.sqrt(n))
	lol = min(lol, k)
	ans = []
	for i in range(min(10 ** 5, k), 0, -1):
		if n % i == 0:
			ans.append(n // i)
			if n // i <= k:
				ans.append(i)
	print(min(ans))


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


import math
t = int(input())
for test in range(0, t):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	p = -1
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n // i <= k:
				p = i
				break
	if p == -1:
		for i in range(int(math.sqrt(n)), 0, -1):
			if n % i == 0 and i <= k:
				p = n // i
				break
	print(p)


import math
import sys
t = int(input())
for q in range(0, t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		m = math.ceil(pow(n, 0.5))
		ans = sys.maxsize
		for i in range(m, 0, -1):
			if n % i == 0:
				div1 = i
				div2 = n // i
				if div1 <= k:
					ans = min(ans, div2)
				if div2 <= k:
					ans = min(ans, div1)
		print(ans)


import math
for i in range(int(input())):
	(n, m) = map(int, input().split())
	s = 0
	mik = float('inf')
	if n == m:
		print(1)
	elif m == 1:
		print(n)
	else:
		for i in range(1, math.ceil(math.sqrt(n)) + 1):
			if n % i == 0:
				if i <= m:
					mik = min(mik, n // i)
				if n // i <= m:
					mik = min(mik, i)
		print(mik)


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)))
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if n <= k:
		print(1)
	else:
		a = sorted(list(factors(n)))
		for i in range(len(a) - 1, -1, -1):
			if a[i] <= k:
				print(int(n / a[i]))
				break


from sys import stdin
input = iter(stdin.readlines()).__next__
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ld = 1
	d = 1
	while d <= n ** 0.5 + 1:
		if n % d == 0:
			if d <= k:
				ld = max(ld, d)
			if n // d <= k:
				ld = max(ld, n // d)
		d += 1
	print(n // ld)


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

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())
	i = 1
	ans = n
	while i ** 2 <= n:
		if n % i == 0:
			sec_div = n // i
			if sec_div <= k:
				ans = min(ans, i)
			if i <= k:
				ans = min(ans, sec_div)
		i += 1
	print(ans)
t = int(input())
for _ in range(t):
	main()


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
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 <= k:
		out(1)
		continue
	i = 2
	answer = n
	while i * i <= n:
		if n % i == 0:
			if i <= k:
				answer = min(answer, n // i)
			if n // i <= k:
				answer = min(answer, i)
		i += 1
	out(answer)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ls = []
	ls2 = []
	i = 1
	while i * i <= n:
		if n % i == 0:
			ls.append(i)
		i += 1
	for i in ls:
		ls2.append(n // i)
	ls += ls2
	l = len(ls)
	ls.sort()
	for i in range(l):
		if ls[i] > k:
			print(n // ls[i - 1])
			break
	else:
		print(n // ls[l - 1])


import math
N = int(input())
ans = []
for _ in range(N):
	(n, t) = map(int, input().split())
	M = int(math.sqrt(n))
	M = min(t, M)
	scop = []
	for i in range(1, M + 1):
		if n % i == 0:
			scop.append(i)
			if n // i <= t:
				scop.append(n // i)
	scop.sort()
	a = scop[-1]
	ans.append(n // a)
for i in ans:
	print(i)


from math import ceil, isqrt

def testCase_1360d():
	return map(int, input().split(' '))

def nPackagesMin(nShovels, nPackageTypes):
	squareRoot_nShovels = isqrt(nShovels)
	nPackagesLowest = ceil(nShovels / nPackageTypes)
	for nPackages in range(nPackagesLowest, min(squareRoot_nShovels, nPackageTypes) + 1):
		if nShovels % nPackages == 0:
			return nPackages
	for packageType in range(min(nPackagesLowest - 1, nPackageTypes), 0, -1):
		if nShovels % packageType == 0:
			return nShovels // packageType
n_testCases = int(input())
testCases = [testCase_1360d() for x in range(n_testCases)]
[print(nPackagesMin(*testCase)) for testCase in testCases]


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 <= k:
		print(1)
	elif k == 1:
		print(n)
	else:
		va = int(sqrt(n))
		lis = [1]
		for i in range(va, 1, -1):
			if n % i == 0:
				ca = n // i
				lis.append(ca)
				lis.append(i)
		lis.sort()
		le = len(lis) - 1
		if len(lis) == 0:
			print(n)
		else:
			for i in range(le, -1, -1):
				if lis[i] <= k:
					print(n // lis[i])
					break


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
		continue
	f = []
	nbyf = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			f.append(i)
			nbyf.append(n // i)
	f = f + list(reversed(nbyf))
	prev = f[0]
	ans = n
	for i in f[1:]:
		if i > k:
			ans = n // prev
			break
		prev = i
	print(ans)


import math
t = int(input())
for afd in range(t):
	line = str(input()).split()
	(n, k) = (int(line[0]), int(line[1]))
	c = 1
	for i in range(1, min(k + 1, math.floor(math.sqrt(n)) + 1)):
		if n % i == 0:
			if n / i <= k:
				c = n / i
				break
			c = max(i, c)
	print(int(n / c))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
		continue
	ans = n
	i = 2
	num = int(n ** 0.5) + 1
	while i < num:
		if n % i == 0:
			if i <= k:
				ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
		i += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ans = n
	i = 1
	while i <= n ** 0.5:
		if n % i == 0 and n // i <= k:
			ans = min(ans, i)
		elif n % i == 0 and i <= k:
			ans = min(ans, n // i)
		i += 1
	print(ans)


def solve():
	from sys import stdin, stdout
	import math
	t = int(stdin.readline())
	while t > 0:
		(n, k) = map(int, input().strip().split())
		l1 = []
		sq = math.sqrt(n)
		for i in range(1, int(sq) + 1):
			if n % i == 0:
				l1.append(i)
				l1.append(n // i)
		l1.sort(reverse=True)
		for i in l1:
			if k < i:
				continue
			else:
				break
		print(n // i)
		t -= 1
solve()


import sys
from collections import defaultdict
import math
input = sys.stdin.readline

def print_result(l):
	return print(' '.join(map(str, l)))

def timer(function):
	import time

	def wrapper(*args, **kwargs):
		t1 = time.time()
		val = function()
		t2 = time.time()
		print('Executed \\{}\\ in {:.2f} seconds.'.format(function.__name__, t2 - t1))
		return val
	return wrapper

def prime_factorization(num, k):
	res = num
	for i in range(2, int(math.sqrt(num)) + 1):
		if num % i == 0:
			(d1, d2) = (num // i, i)
			if d1 <= k:
				res = min(res, d2)
			if d2 <= k:
				res = min(res, d1)
	return res

def solve():
	(n, k) = map(int, input().split(' '))
	if k >= n:
		res = 1
	else:
		res = prime_factorization(n, k)
	print(res)
t = int(input())
for _ in range(t):
	solve()


import sys
input = sys.stdin.readline

def solve():
	(n, k) = map(int, input().split())
	answer = n
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i <= k:
				answer = min(answer, n // i)
			if n // i <= k:
				answer = min(answer, i)
	print(answer)
T = int(input())
for i in range(T):
	solve()


from math import *
from copy import *
from heapq import *
from string import *
from random import *
from bisect import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
from collections import defaultdict

def solve(l):
	(n, k) = l
	facts = set()
	for i in range(1, ceil(sqrt(n)) + 1):
		if n % i == 0:
			if i <= k:
				facts.add(i)
			if n // i <= k:
				facts.add(n // i)
	facts = list(facts)
	facts.sort()
	return n // facts[-1]
T = int(input())
for _ in range(T):
	l = list(map(int, stdin.readline().rstrip().split()))
	print(solve(l))


import math
t = int(input())
for y in range(0, t):
	(n, k) = list(map(int, input().split()))
	i = 1
	ans = n
	while i * i <= n and i <= k:
		if n % i == 0:
			if n // i <= k:
				ans = i
				break
			ans = min(ans, n // i)
		i += 1
	print(ans)


import collections
from math import sqrt

def solve(n, k):
	f = []
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			f.append(i)
			f.append(n // i)
	f.sort(reverse=True)
	for i in f:
		if i <= k:
			return n // i
t = int(input().strip())
for i in range(t):
	[n, k] = list(map(int, input().strip().split()))
	print(solve(n, k))


from math import radians
from heapq import heapify, heappush, heappop
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)
for _ in range(ii()):
	(n, k) = mi()
	if k >= n:
		print(1)
	else:
		x = n
		ans = 0
		f = []
		for i in range(1, int(sqrt(x)) + 1):
			if n % i == 0:
				f.append(i)
				if i != n // i:
					f.append(n // i)
		f = sorted(f)
		for i in f:
			if i > ans and i <= k:
				ans = i
				re = n // i
			else:
				print(re)
				break


from math import sqrt

def divisors(n):
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			yield i
			yield (n // i)

def buy(n, k):
	if n <= k:
		return 1
	return next((n // x for x in sorted(divisors(n), reverse=True) if x <= k))

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


import sys
from math import sqrt
t = int(input())
for tc in range(t):
	(n, k) = map(int, input().split())
	mf = 1
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if i <= k:
				mf = max(mf, i)
			if n // i <= k:
				mf = max(mf, n // i)
	print(n // mf)


import math
from math import gcd
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	elif n % k == 0:
		print(n // k)
	else:
		a = True
		ans = n
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0:
				if n // i <= k:
					ans = min(ans, i)
				elif i <= k:
					ans = min(n // i, ans)
				else:
					continue
		print(ans)


import sys
import math
import itertools
import random
from collections import deque

def solve():
	(n, k) = map(int, input().split())
	a = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			a.append(i)
			a.append(n / i)
	a.sort()
	div = 1
	for num in a:
		if num > k:
			break
		div = num
	print(int(n / div))
t = int(input())
while t > 0:
	solve()
	t -= 1


import sys
from bisect import bisect
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(II()):
		(n, k) = MI()
		ans = -1
		dd = []
		for d in range(1, n + 1):
			if d ** 2 > n:
				break
			if n % d == 0:
				dd.append(d)
				if n // d <= k:
					ans = d
					break
		if ans == -1:
			i = bisect(dd, k)
			print(n // dd[i - 1])
		else:
			print(ans)
main()


def prime(a, k):
	if a == 1 or a == 2 or a == 3:
		return a
	else:
		check = 2
		point = 0
		best = 0
		while check * check <= a and check <= k:
			if a % check == 0:
				point = 1
				temp = a // check
				if temp <= k:
					return check
				else:
					best = temp
				check += 1
			else:
				check += 1
		if point == 0:
			return a
		else:
			return best
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	elif k == 1:
		print(n)
	else:
		print(prime(n, k))


import bisect

def fac(n):
	ans = set()
	x = 1
	while x * x <= n:
		m = 0
		if n % x == m:
			ans.add(x)
			ans.add(n // x)
		x = x + 1
	return list(ans)
for _ in range(0, int(input())):
	(n, k) = list(map(int, input().split()))
	if n <= k:
		x = 1
		print(x)
	elif n % k == 0:
		g = n // k
		print(g)
	else:
		factors = fac(n)
		f = sorted(factors)
		index = bisect.bisect_left(f, k)
		x = index - 1
		for i in range(x, -1, -1):
			if n % f[i] == 0:
				ans = n // f[i]
				print(ans)
				break


for p in range(0, int(input())):
	d = list(map(int, input().split(' ')))
	div = []
	sqrt = int(d[0] ** (1 / 2))
	for i in range(1, sqrt + 1):
		if d[0] % i == 0:
			div.append(i)
			if i != d[0] ** (1 / 2):
				div.append(int(d[0] / i))
	div.sort()
	mostrar = d[0]
	for i in range(0, len(div)):
		if d[1] == div[i]:
			mostrar = int(d[0] / div[i])
			break
		if div[i] < d[1]:
			mostrar = int(d[0] / div[i])
	print(mostrar)


for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	z = n
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i <= k:
				z = min(z, n // i)
			if n // i <= k:
				z = min(z, i)
	print(z)


import math

def get_biggest_divisor(n, k):
	d = 1
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if i <= k:
				d = max(d, i)
			if n // i <= k:
				d = max(d, n // i)
	return d

def solve():
	(n, k) = map(int, input().split())
	d = get_biggest_divisor(n, k)
	print(n // d)
t = int(input())
for _ in range(t):
	solve()


def question_D(n, k):
	factors = []
	for d in range(1, int(n ** 0.5) + 1):
		if n % d == 0:
			factors.append(d)
			factors.append(n // d)
	factors.sort(reverse=True)
	for d in factors:
		if d <= k:
			print(n // d)
			break
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	question_D(x, y)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	factors = []
	for d in range(1, int(n ** 0.5) + 1):
		if n % d == 0:
			factors.append(d)
			factors.append(n // d)
	factors.sort(reverse=True)
	for d in factors:
		if d <= k:
			print(n // d)
			break


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(reverse=True)
	return divisors
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		arr = make_divisors(n)
		for i in arr:
			if i <= k:
				print(n // i)
				break


import math
t = int(input())
for q in range(t):
	(a, b) = map(int, input().split())
	if b >= a:
		print(1)
	else:
		ans = -1
		for i in range(2, int(a ** 0.5) + 1):
			if i > b:
				break
			if a % i == 0:
				ans = max(ans, i)
				if a // i <= b:
					ans = max(ans, a // i)
		print(a // ans if ans != -1 else a)


def f():
	(a, b) = map(int, input().split())
	s = isPrime(a)
	s = sorted(list(s), reverse=True)
	for i in s:
		if i <= b:
			print(a // i)
			return

def isPrime(x):
	s = set()
	for i in range(1, int(x ** 0.5) + 1):
		if x % i == 0:
			s.add(i)
			s.add(x // i)
	return s
t = input()
for i in range(int(t)):
	f()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, functools

def solve(line):
	(n, k) = map(int, line.split())
	if n <= k:
		return 1
	ans = n
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			ans = min(ans, i if n / i <= k else n, n // i if i <= k else n)
	return ans
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
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	nn = n
	ans = []
	if n <= k:
		print(1)
		continue
	for i in range(int(math.sqrt(n)) + 1, 0, -1):
		if n % i == 0:
			a = n / i
			b = i
			if max(a, b) <= k:
				ans.append(int(n / max(a, b)))
			elif min(a, b) <= k:
				ans.append(int(n / min(a, b)))
	print(min(ans))


from math import sqrt

def ans(n, k):
	if n <= k:
		return 1
	if n == 2 or n == 3:
		return n
	z = int(sqrt(n))
	fac = []
	for i in range(2, z + 1):
		if n % i == 0:
			fac.append(i)
	if fac == []:
		return n
	fac1 = [i for i in fac]
	for i in range(len(fac) - 1, -1, -1):
		fac1.append(n // fac[i])
	lo = 1
	i = 0
	while i < len(fac1):
		if k >= lo and k < fac1[i]:
			return n // lo
		lo = fac1[i]
		i += 1
	return n // fac1[-1]
m = int(input())
for i in range(m):
	a = input().split()
	n = int(a[0])
	k = int(a[1])
	print(ans(n, k))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		l = min(int(n ** 0.5) + 1, k)
		j = 2
		an = 1
		while j <= l:
			if n % j == 0:
				if n // j <= k:
					an = n // j
					j = k + 1
				else:
					an = j
			j = j + 1
		print(n // an)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 1
	l = []
	for i in range(1, int(n ** (1 / 2) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	l.sort(reverse=True)
	for i in l:
		if i <= k:
			break
	print(n // i)


def make_divisors(n: int) -> list:
	divisors = []
	for k in range(1, int(n ** 0.5) + 1):
		if n % k == 0:
			divisors.append(k)
			if k != n // k:
				divisors.append(n // k)
	divisors = sorted(divisors)
	return divisors
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	divs = make_divisors(n)
	ans = 10 ** 18
	for div in divs:
		if div <= k:
			ans = min(ans, n // div)
	print(ans)


import math
T = int(input())
for test in range(T):
	(n, k) = map(int, input().split())
	max_cur = 1
	for i in range(int(math.sqrt(n)), 0, -1):
		if n % i == 0:
			if i <= k:
				if n // i <= k:
					max_cur = max(max_cur, max(n // i, i))
				max_cur = max(max_cur, i)
	print(n // max_cur)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	i = 1
	ans = 1
	li = []
	li2 = []
	while i ** 2 <= n:
		if n % i == 0:
			if i <= k:
				ans = max(ans, i)
			if n // i <= k:
				ans = max(ans, n // i)
		i += 1
	print(n // ans)


import math
t = int(input())
for u in range(t):
	(n, k) = list(map(int, input().split()))
	fact = [1]
	for i in range(2, int(math.sqrt(n)) + 2):
		if n % i == 0:
			fact.append(i)
	haj = len(fact)
	for i in range(haj):
		fact.append(n // fact[i])
	u = list(sorted(fact))
	gd = int(n)
	for i in range(len(u)):
		if u[i] > k:
			gd = u[i - 1]
			break
	print(n // gd)


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)))
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		l = list(factors(n))
		l.sort(reverse=True)
		for i in l:
			if i <= k:
				print(n // i)
				break


t = int(input())
import math
for i in range(t):
	(b, p) = [int(x) for x in input().split()]
	if b <= p:
		print(1)
	else:
		cd = 0
		rem = b
		pack = 0
		ans = b
		e = int(math.sqrt(b)) + 1
		for i in range(e, 0, -1):
			if b % i == 0:
				if i <= p and b // i < ans:
					ans = b // i
				if b // i <= p and b // (b // i) < ans:
					ans = b // (b // i)
		print(ans)


import math

def shovels(n, k):
	if k >= n:
		return 1
	else:
		x = int(math.sqrt(n))
		out = n
		for i in range(1, x + 1):
			if n % i == 0:
				if i <= k:
					out = min(out, n // i)
				if n // i <= k:
					out = min(out, i)
		return out
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(shovels(n, k))


from collections import defaultdict, Counter
from functools import lru_cache
from heapq import heappush, heappop
from math import gcd, floor, ceil, sqrt
from sys import stdin, stdout

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

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

def istr():
	return stdin.readline().strip()

def solve(n, k):
	res = 1
	t = int(ceil(sqrt(n)))
	for i in range(1, t + 1):
		if n % i == 0:
			(x, y) = (i, n // i)
			if x <= k:
				res = max(res, x)
			if y <= k:
				res = max(res, y)
	return n // res
t = iint()
for _ in range(t):
	(n, k) = ilist()
	print(solve(n, k))


import sys
input = sys.stdin.readline
import math

def divs(n, k):
	ans = 1
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			j = n // i
			if i <= k:
				ans = max(ans, i)
			if j <= k:
				ans = max(ans, j)
	return n // ans
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	print(divs(n, k))


from math import sqrt
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		x = n
		ans = 0
		f = []
		for i in range(1, int(sqrt(x)) + 1):
			if n % i == 0:
				f.append(i)
				if i != n // i:
					f.append(n // i)
		f = sorted(f)
		for i in f:
			if i > ans and i <= k:
				ans = i
				re = n // i
			else:
				print(re)
				break


import math
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	x = min(math.ceil(n ** 0.5), k)
	u = n
	if k >= n:
		print(1)
		continue
	for i in range(x, 0, -1):
		if n % i == 0:
			if n // i <= k:
				u = min(i, u)
			else:
				u = min(n // i, u)
	print(u)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		m = n
		for i in range(2, min(int(n ** 0.5) + 1, k + 1)):
			if n % i == 0:
				if n // i <= k:
					m = min(m, i)
				else:
					m = min(m, n // i)
		print(m)


import sys
input = sys.stdin.readline
from math import sqrt
t = int(input())
for tests in range(t):
	(n, k) = map(int, input().split())
	xr = int(sqrt(n))
	LIST = []
	for i in range(1, xr + 1):
		if n % i == 0:
			LIST.append(i)
			LIST.append(n // i)
	if k >= n:
		print(1)
	else:
		ANS = n
		for i in LIST:
			if i <= k:
				ANS = min(ANS, n // i)
		print(ANS)


t = int(input())
for test in range(t):
	(n, k) = [int(x) for x in input().split()]
	if k >= n:
		print(1)
		continue
	else:
		import math
		i = int(math.sqrt(n)) + 1
		ans = []
		while i >= 1:
			if n % i == 0:
				if n / i == i and i <= k:
					ans.append(i)
				if i <= k:
					ans.append(i)
					if n // i <= k:
						ans.append(n // i)
			i = i - 1
		print(n // max(ans))


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)
	for m in d:
		if k >= n // m >= 1:
			print(m)
			break


from math import floor, sqrt

def factors(number):
	factors_dict = []
	for i in range(1, floor(sqrt(number)) + 1):
		if number % i == 0:
			factors_dict.extend([i, number // i])
	return sorted(factors_dict, reverse=True)
number_inputs = int(input())
user_list = []
for j in range(number_inputs):
	user_input = input()
	new_addition = user_input.split(' ')
	new_addition = [int(i) for i in new_addition]
	user_list.append(new_addition)
for item in user_list:
	current_factors = factors(item[0])
	for k in current_factors:
		if k > item[1]:
			continue
		print(item[0] // k)
		break


N = int(input())
for i in range(N):
	(a, b) = map(int, input().split())
	ans = a
	for j in range(1, int(a ** 0.5) + 5):
		if a % j == 0 and a <= b * j:
			ans = min(ans, j)
		if a % j == 0 and a // (a // j) <= b:
			ans = min(ans, a // j)
	print(ans)


def solve():
	(n, k) = map(int, input().split())
	lv = [1]
	v = 2
	while v * v <= n:
		if n % v == 0:
			lv.append(v)
			if n // v != v:
				lv.append(n // v)
		v += 1
	lv.append(n)
	lv.sort()
	ans = 1
	av = [n]
	for value in lv[1:]:
		if value <= k:
			av.append(n // value)
			ans = value
	print(n // ans)
t = int(input())
while t > 0:
	t -= 1
	solve()


import math

def solution():
	(n, k) = map(int, input().split())
	ans = 1000000000
	for i in range(1, math.ceil(n ** (1 / 2)) + 1):
		if i > k:
			break
		if n % i == 0:
			ans = min(n // i, ans)
			if n // i <= k:
				ans = min(i, ans)
	print(ans)
for _ in range(int(input())):
	solution()


def make_divisors(n):
	(lower_divisors, upper_divisors) = ([], [])
	i = 1
	while i * i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n // i)
		i += 1
	return lower_divisors + upper_divisors[::-1]
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	divs = make_divisors(n)
	for d in reversed(divs):
		if d > k:
			continue
		print(n // d)
		break


INF = 10 ** 18
t = int(input())

def solve():
	(n, k) = map(int, input().split())
	a = []
	i = 1
	while i * i <= n:
		if n % i == 0:
			a.append(i)
			a.append(n // i)
		i += 1
	i = 1
	for d in a:
		if d <= k:
			i = max(i, d)
	print(n // i)
for tt in range(t):
	solve()


for d in [*open(0)][1:]:
	(n, k) = map(int, d.split())
	ans = n
	i = 1
	while i * i <= n and i <= k:
		if n % i == 0:
			if n // i <= k:
				ans = i
				break
			ans = min(ans, n // i)
		i += 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

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

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')

def main():
	for _ in range(iin()):
		(n, k) = ain()
		if n <= k:
			print(1)
		else:
			i = 1
			mini = MAX
			while i <= min(k, n ** 0.5):
				if n % i == 0:
					mini = min(mini, n // i)
					if n // i <= k:
						mini = min(mini, i)
				i += 1
			print(mini)
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')
main()


t = int(input())
while t:
	(a, b) = map(int, input().split())
	i = 1
	l = []
	l1 = []
	while i * i <= a:
		if i > b:
			break
		if a % i == 0:
			x = a // i
			if x <= b:
				l.append(i)
				l.append(x)
			else:
				l1.append(x)
		i = i + 1
	if len(l) == 0 and len(l1) == 0:
		print(a)
	elif len(l1) == 0:
		print(min(l))
	elif len(l) == 0:
		print(min(l1))
	else:
		print(min(min(l), min(l1)))
	t = t - 1


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

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

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

def invr():
	return map(int, input().split())
entries = inp()
for i in range(entries):
	l = inlt()
	n = l[0]
	k = l[1]
	i = 1
	ans = 1
	flag = 1
	while i * i <= n and i <= k:
		if n % i == 0:
			if n / i <= k:
				print(int(i))
				flag = 0
				break
			else:
				ans = i
		i += 1
	if flag:
		print(n // ans)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n
	i = 1
	while i * i <= n and i <= k:
		if n % i == 0:
			if n // i <= k:
				ans = i
				break
			ans = min(ans, n // i)
		i += 1
	print(ans)


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	g = int(n ** 0.5)
	minn = n
	for i in range(1, g + 2):
		if n % i == 0:
			if n // i <= k:
				minn = min(minn, i)
				break
			if i <= k:
				minn = min(minn, n // i)
	print(minn)


from math import *
import sys
input = sys.stdin.buffer.readline
a = int(input())
for x in range(a):
	(b, c) = map(int, input().split())
	d = int(sqrt(b)) + 1
	ma = 0
	if c > b:
		print(1)
	else:
		for z in range(1, d):
			if b % z == 0:
				if int(b / z) == z:
					if z <= c:
						ma = max(ma, z)
				else:
					if z <= c:
						ma = max(ma, z)
					if int(b / z) <= c:
						ma = max(ma, b / z)
		print(int(b / ma))


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()
	best = n
	for i in range(1, min(k, int(n ** 0.5)) + 1):
		if n % i == 0:
			best = min(best, n // i)
			if n // i <= k:
				best = min(best, i)
	print(best)
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


from math import sqrt
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	divisors = set()
	sqrtn = int(sqrt(n))
	for i in range(1, sqrtn + 1):
		if n % i == 0:
			divisors.add(i)
			divisors.add(n // i)
	divisors = list(divisors)
	divisors.sort(reverse=True)
	length = len(divisors)
	done = False
	for i in range(length):
		if divisors[i] <= k:
			print(n // divisors[i])
			done = True
			break
	if not done:
		print(n)


def factors(n):
	l = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
for t in range(int(input())):
	(n, k) = map(int, input().split())
	l = factors(n)
	l.sort(reverse=True)
	for i in l:
		if i <= k:
			print(n // i)
			break


def largest_factor(n, k):
	divisible = 2
	temp = 1
	solutions = [1]
	while divisible * divisible <= n:
		if divisible > k:
			break
		if n % divisible == 0:
			solutions.append(divisible)
			temp = n // divisible
			if temp <= k:
				solutions.append(temp)
		divisible += 1
	return solutions
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		answer = largest_factor(n, k)
		answer.sort()
		print(n // answer[-1])


import math
T = int(input())

def divs(n):
	d = []
	for i in range(1, math.ceil(math.sqrt(n)) + 1):
		if n % i == 0:
			d.extend([i, n // i])
	return sorted(d)
for t in range(T):
	(N, K) = [int(_) for _ in input().split()]
	for d in divs(N):
		if N / d <= K:
			print(d)
			break


import math

def gd(n):
	i = 1
	l = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n / i)
		i = i + 1
	return l
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = gd(n)
	l.sort(reverse=True)
	val = l[-1]
	for i in l:
		if i <= k:
			val = i
			break
	val = int(val)
	print(n // val)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
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(input())):
	(n, k) = l()
	div = [1]
	for i in range(2, min(k, int(n ** 0.5)) + 1):
		if n % i == 0:
			div.append(i)
	m = n
	for ele in div:
		if ele <= k:
			m = min(m, n // ele)
		if n // ele <= k:
			m = min(ele, m)
	print(m)


import sys
from collections import deque
input = sys.stdin.buffer.readline
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	minVal = n
	for i in range(1, min(int(n ** 0.5) + 2, k + 1)):
		if n % i == 0 and k >= n // i:
			minVal = min(minVal, i)
		elif n % i == 0:
			minVal = min(minVal, n // i)
	print(minVal)


import sys, heapq
from collections import *
from functools import lru_cache
sys.setrecursionlimit(10 ** 6)

def main():
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split(' '))
		(fmin, fmax, res) = (1, a, a)
		while fmin * fmin <= a:
			if a % fmin == 0:
				fmax = a // fmin
				if fmax <= b:
					break
				if fmin <= b:
					res = fmax
			fmin += 1
		if fmax <= b:
			print(fmin)
		else:
			print(res)
main()


from math import sqrt

def ps(n, a):
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				a.append(i)
			else:
				a.append(i)
				a.append(n // i)
	return a
for zx in range(int(input())):
	(n, k) = map(int, input().split())
	s = ps(n, [])
	h = []
	for i in range(len(s)):
		t = s[i]
		if t <= k:
			h.append(t)
	o = max(h)
	print(n // o)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = []
	i = 1
	l.append(1)
	while i * i <= n:
		if n % i == 0:
			l.append(i)
			l.append(n // i)
		i += 1
	if n <= k:
		print(1)
	else:
		l.sort(reverse=True)
		for i in l:
			if n % i == 0 and i <= k:
				print(n // i)
				break


import math
t = int(input())

def divisors(n, k):
	i = 1
	ll = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				ll.append(i)
			else:
				ll.append(i)
				ll.append(n // i)
		i += 1
	return ll
for _ in range(t):
	(n, k) = map(int, input().split())
	ll = divisors(n, k)
	ll.sort()
	if k >= n:
		print(1)
		continue
	ind = len(ll) - 1
	while ind >= 0:
		if ll[ind] <= k:
			break
		else:
			ind -= 1
	print(n // ll[ind])


import sys
sys.setrecursionlimit(10 ** 7)
stdin = sys.stdin
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
import math
import bisect

def make_divisors(n):
	(lower_divisors, upper_divisors) = ([], [])
	i = 1
	while i * i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n // i)
		i += 1
	return lower_divisors + upper_divisors[::-1]
t = ni()
for i in range(t):
	(n, k) = na()
	if n <= k:
		print(1)
	else:
		li = make_divisors(n)
		p = 1
		for i in range(len(li)):
			if k < li[i]:
				break
			p = li[i]
		if n % p == 0:
			print(n // p)
		else:
			print(n // p + 1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		p = n
		for t in range(1, int(n ** 0.5) + 1):
			if n % t == 0 and t <= k:
				p = min(p, n // t)
			if n % t == 0 and n / t <= k:
				p = min(p, t)
		print(p)


from pprint import pprint
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)
	return divisors
q = int(input())
for _ in range(q):
	(n, k) = map(int, input().split())
	l = make_divisors(n)
	l.sort(reverse=True)
	for item in l:
		if k >= item:
			print(n // item)
			break


def solve(n, k):
	if k >= n:
		return 1
	div = None
	ans = n
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			div = n // i
			if div <= k:
				return i
			elif i <= k:
				ans = div
			else:
				break
	return ans
t = int(input())
for i in range(t):
	(n, k) = tuple(map(int, input().split()))
	print(solve(n, k))


def solution():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		m = 2000000000.0
		l = []
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				l.append(i)
				l.append(n // i)
		l.sort(reverse=True)
		for i in range(len(l)):
			if l[i] <= k:
				print(n // l[i])
				break
solution()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		sq = int(n ** 0.5) + 1
		a = []
		b = []
		f = 0
		for i in range(1, sq):
			if n % i == 0:
				a.append(i)
				x = n // i
				if x <= k:
					ans = n // x
					f = 1
					break
		if f == 1:
			print(ans)
		else:
			a = a[::-1]
			for y in a:
				if y <= k:
					print(n // y)
					break


import math
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().strip().split()))
	ans = -1
	for i in range(1, math.floor(math.sqrt(n)) + 1):
		if n % i == 0:
			fact1 = i
			fact2 = n // i
			if fact1 <= k:
				if fact1 > ans:
					ans = fact1
			if fact2 <= k:
				if fact2 > ans:
					ans = fact2
	print(n // ans)


def solve(n, k):
	factors = []
	for i in range(1, int(n ** 0.5) + 1):
		if not n % i:
			factors.append(i)
			factors.append(n // i)
	factors = sorted(factors, reverse=1)
	for i in factors:
		if i <= k:
			return n // i

def main():
	t = int(input())
	for i in range(t):
		(n, k) = list(map(int, input().split()))
		print(solve(n, k))
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = int(n ** 0.5 + 1)
	a = n
	for i in range(1, l):
		if n % i == 0:
			r = n // i
			if r <= k:
				a = min(a, i)
			if i <= k:
				a = min(a, r)
	print(a)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	out = n
	i = 1
	while i * i <= n:
		if n % i == 0:
			if i <= k:
				out = min(out, n // i)
			if n // i <= k:
				out = min(out, i)
		i += 1
	print(out)


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 tuple(map(int, input().split()))

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

def Int():
	return int(input())

def Str():
	return input()

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

def prime(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 check(n, k):
	ans = inf
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0 and i <= k:
			ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
	return ans
for _ in range(Int()):
	(n, k) = value()
	if n <= k:
		print(1)
	elif prime(n) == True:
		print(n)
	elif k == 1:
		print(n)
	else:
		print(check(n, k))


t = int(input())
for ti in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	factors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i <= k:
				factors.append(i)
			if int(n / i) <= k:
				factors.append(int(n / i))
	print(int(n / max(factors)))


from collections import Counter
import sys
sys.setrecursionlimit(10 ** 6)
mod = 1000000007
inf = int(1e+18)
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]

def inverse(a):
	return pow(a, mod - 2, mod)

def usearch(x, a):
	lft = 0
	rgt = len(a) + 1
	while rgt - lft > 1:
		mid = (rgt + lft) // 2
		if a[mid] <= x:
			lft = mid
		else:
			rgt = mid
	return lft

def solve():
	(n, k) = map(int, input().split())
	ans = inf
	i = 1
	while i * i <= n and i <= k:
		if n % i == 0:
			ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, n // (n // i))
		i += 1
	if n <= k:
		ans = 1
	print(ans)

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


from sys import stdin
from math import sqrt
input = stdin.readline
R = lambda : map(int, input().split())
for _ in range(int(input())):
	(n, k) = R()
	v = []
	for i in range(1, round(sqrt(n)) + 1):
		if n % i == 0:
			p = n // i
			if p <= k:
				v += (i,)
			elif i <= k:
				v += (p,)
	print(min(v))


import math
from sys import stdin, stdout

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

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

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

def main():
	for i in range(int(input())):
		(n, k) = In()
		if k >= n:
			print(1)
		else:
			ans = -1
			for i in range(1, int(math.sqrt(n)) + 1):
				if i > k:
					break
				if n % i == 0:
					ans = max(ans, i)
					if n // i <= k:
						ans = max(ans, n // i)
			print(n // ans if ans != -1 else n)
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	elif k >= n // 2 and n % 2 == 0:
		print(2)
	else:
		maxx = n
		if k >= int(n ** 0.5) + 1:
			for i in range(2, int(n ** 0.5) + 1):
				if n % i == 0:
					if n // i <= k:
						maxx = i
						break
					else:
						maxx = n // i
		else:
			for i in range(1, k + 1):
				if n % i == 0:
					maxx = n // i
		print(maxx)


def factors(n):
	l = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			l.append(i)
			l.append(n // i)
	return sorted(set(l))
for i in range(int(input())):
	(n, k) = map(int, input().split())
	ans = float('inf')
	for f in factors(n):
		if f <= k:
			ans = min(ans, n // f)
		else:
			break
	print(ans)


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	divisor = []
	if k >= n:
		print(1)
	else:
		flag = 0
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				divisor.append(i)
				if n // i <= k:
					print(i)
					flag = 1
					break
		if flag == 0:
			for ii in range(len(divisor) - 1, -1, -1):
				if divisor[ii] <= k:
					print(n // divisor[ii])
					break


def getPrimes(n):
	primes = []
	for i in range(2, int(n ** 0.5) + 1):
		while n % i == 0:
			primes.append(i)
			n //= i
	if n != 1:
		primes.append(n)
	return primes
div = 1

def findDiv(n, k, primes, i=0, cur=1):
	global div
	if cur <= min(n, k):
		div = max(div, cur)
	if i >= len(primes):
		return
	findDiv(n, k, primes, i + 1, cur * primes[i])
	for j in range(i + 1, len(primes)):
		if primes[j] != primes[i]:
			findDiv(n, k, primes, j, cur)
			break
for t in range(int(input())):
	(n, k) = (int(x) for x in input().split())
	div = 1
	primes = getPrimes(n)
	findDiv(n, k, primes)
	print(n // div)


from sys import stdin
from math import ceil, sqrt

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
	prime[0] = False
	prime[1] = False
	return prime
input = stdin.readline

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

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

def factors(n, k):
	l = []
	m = 1
	for i in range(1, min(k, ceil(sqrt(n))) + 1):
		if n % i == 0:
			if n // i == i:
				if i > m and i <= k:
					m = i
			else:
				if i > m and i <= k:
					m = i
				if n // i > m and n // i <= k:
					m = n // i
	return m
for _ in range(int(input())):
	(n, k) = sep_input()
	print(n // factors(n, k))


import math
t = int(input())
while t > 0:
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	ans = 0
	if k >= n:
		ans = 1
	elif k == 1:
		ans = n
	else:
		li = []
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0:
				li.append(i)
				if i != n // i:
					li.append(n // i)
		if len(li) == 0:
			ans = n
		else:
			li.sort()
			for i in range(len(li) - 1, -1, -1):
				if li[i] <= k:
					ans = n / li[i]
					break
				if i == 0:
					ans = n
	print(int(ans))
	t -= 1


import sys

def arr():
	return list(map(int, input().split()))
input = sys.stdin.readline
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	ans = float('inf')
	for i in range(1, int(N ** 0.5) + 1):
		if N % i == 0:
			x = N // i
			y = i
			if x <= K and y <= K:
				ans = min(ans, min(x, y))
			elif x > K and y <= K:
				ans = min(ans, x)
			elif x <= K and y > K:
				ans = min(ans, y)
	print(ans)


from math import sqrt, ceil
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	low = n
	if k >= n:
		print(1)
	else:
		for i in range(1, ceil(sqrt(n)) + 1):
			if n % i == 0:
				if i <= k:
					low = min(low, n // i)
				if n // i <= k:
					low = min(low, i)
		print(low)


import math

def main():
	(n, k) = (int(x) for x in input().split())
	if k >= n:
		return 1
	d = 1
	for i in range(2, math.ceil(math.sqrt(n) + 1)):
		if n % i == 0:
			if i <= k:
				d = max(d, i)
			if n // i <= k:
				d = max(d, n // i)
	return n // d
t = int(input())
while t > 0:
	t -= 1
	ans = main()
	print(ans)


import math

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		if n <= k:
			print(1)
			continue
		else:
			ans = n
			for i in range(1, int(math.sqrt(n)) + 1):
				if n % i == 0:
					if n // i <= k:
						ans = min(i, ans)
					if i <= k:
						ans = min(n // i, ans)
			print(ans)
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	elif k == 1:
		print(n)
	else:
		c = int(n ** (1 / 2)) + 1
		l = []
		if c > k:
			c = k
		for i in range(2, c + 1):
			if n % i == 0:
				l.append(i)
		if len(l) == 0:
			print(n)
		else:
			u = []
			for e in l:
				c = n // e
				if c <= k:
					u.append(c)
			l = u + l
			print(n // max(l))


import sys
import math

def divisor(n):
	if n == 1:
		return [1]
	res = [1, n]
	for i in range(2, 1 + math.floor(n ** 0.5)):
		if n % i == 0:
			res.append(i)
			if i != n // i:
				res.append(n // i)
	res.sort()
	return res
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
t = int(input())
for case in range(t):
	(n, k) = list(map(int, input().split()))
	lis = divisor(n)
	ans = 1
	for i in lis:
		if i <= k:
			ans = i
	print(n // ans)


from collections import deque
from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	now = 2
	mx = n if k >= n else 1
	while now ** 2 <= n:
		if n % now == 0:
			if now <= k:
				mx = max(mx, now)
			bf = n // now
			if bf <= k:
				mx = max(bf, mx)
		now += 1
	print(n // mx)


def divisors(n):
	result = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			result.append(i)
			result.append(n // i)
	result.sort(reverse=True)
	return result

def solve():
	(n, k) = map(int, input().split())
	if n < k:
		print(1)
	else:
		divs = divisors(n)
		for d in divs:
			if d <= k and n % d == 0:
				print(n // d)
				return 0

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


import math

def divisors(i):
	divs = set()
	for div in range(1, math.ceil(math.sqrt(i)) + 1):
		if i % div == 0:
			divs.add(div)
			divs.add(i // div)
	return divs

def solve(n, k):
	divs = sorted(divisors(n), reverse=True)
	for d in divs:
		if d <= k:
			return n // d
	assert False

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


import bisect
import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = []
	b = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			a.append(i)
			if b == []:
				b.append(n // i)
			else:
				b.insert(0, n // i)
	a.extend(b)
	res = bisect.bisect(a, k)
	print(n // a[res - 1])


import io
import os
import functools
import itertools
import math
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
while t:
	t -= 1
	(n, k) = [int(x) for x in input().split()]
	div = []
	i = 1
	while i * i <= n and i <= k:
		if not n % i:
			div.append(n // i)
			if n // i <= k:
				div.append(i)
		i += 1
	print(min(div))


def calc(n, k):
	res = int(1000000000000.0)
	for i in range(1, int(round(n ** 0.5)) + 1):
		if n % i == 0:
			if i <= k:
				res = min(res, n // i)
			if n // i <= k:
				res = min(res, i)
	return res
t = int(input())
for i in range(t):
	(n, k) = [int(i) for i in input().split()]
	print(calc(n, k))


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

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans
from math import *
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 0
	if n <= k:
		print(1)
		continue
	li = []
	temp = int(sqrt(n))
	for i in range(1, temp + 1):
		if n % i == 0 and i <= k:
			if n // i <= k:
				li.append((n // i, i))
				li.append((i, n // i))
			else:
				li.append((n // i, i))
	li.sort()
	print(li[0][0])


from math import sqrt

def solve(n, k):
	ans = 0
	for j in range(min(int(sqrt(n)), k), 0, -1):
		if n % j == 0:
			if j > ans:
				ans = j
			if n // j > ans and n // j <= k:
				ans = n // j
	return n // ans
arr = []
for s in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	if k >= n:
		arr.append(1)
	else:
		arr.append(solve(n, k))
for it in arr:
	print(it)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = []
	if n <= k:
		print(1)
	else:
		for i in range(1, int(math.ceil(math.sqrt(n))) + 1):
			if n % i == 0 and i <= k:
				l.append(i)
				if n // i <= k:
					l.append(n // i)
		print(n // max(l))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n
	if n <= k:
		print(1)
	else:
		for j in range(1, int(n ** 0.5 + 1)):
			if n % j == 0:
				if j <= k:
					ans = min(ans, n / j)
				if n / j <= k:
					ans = min(ans, j)
		print(int(ans))


import math
t = int(input())

def getDivisors(n, k):
	g = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				g.append(i)
			else:
				g.append(i)
				g.append(n // i)
		i = i + 1
	z = []
	for i in range(len(g)):
		if g[i] <= k:
			z.append(g[i])
	return z
for _ in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		g = getDivisors(n, k)
		print(n // max(g))


import math
from bisect import bisect_left as bi

def printDivisors(n):
	i = 1
	a = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				a.append(i)
			else:
				a.extend([i, n // i])
		i = i + 1
	return a
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	b = printDivisors(n)
	b.sort()
	c = bi(b, k)
	if c != len(b):
		if b[c] == k:
			print(n // k)
		elif c != 0:
			print(n // b[c - 1])
	elif c != 0:
		print(n // b[c - 1])


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().strip().split()))
	j = 1
	ans = n
	while j * j <= n:
		if n % j == 0:
			if j <= k:
				ans = min(ans, n // j)
			if n // j <= k:
				ans = min(ans, j)
		j += 1
	if n <= k:
		print(1)
	else:
		print(ans)


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 i in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print('1')
	elif k == 1:
		print(n)
	else:
		a = list(factors(n))
		a.sort(reverse=True)
		for j in range(len(a)):
			if a[j] <= k:
				print(n // a[j])
				break


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	d = []
	for i in range(1, 1 + int(n ** 0.5)):
		if not n % i:
			d.append(i)
			d.append(n // i)
	d = sorted(list(set(d)))
	m = len(d) - 1
	for i in range(len(d)):
		if d[i] > k:
			m = i - 1
			break
	print(n // d[m])


def factors(x):
	result = []
	i = 1
	while i * i <= x:
		if x % i == 0:
			result.append(i)
			if x // i != i:
				result.append(x // i)
		i += 1
	return result
import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = factors(a)
	l.sort(reverse=True)
	if b >= a:
		print(1)
	else:
		ans = 999999999999999
		i = 0
		while ans != 0:
			if l[i] <= b:
				ans = 0
				print(a // l[i])
			i = i + 1


from sys import stdin
import math
for _ in range(int(stdin.readline())):
	(n, k) = list(map(int, stdin.readline().split()))
	res = n
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n // i <= k and i <= res:
				res = i
			elif i <= k and n // i <= res:
				res = n // i
	print(res)


def factors(n):
	k = 1
	output = []
	while k * k <= n:
		if n % k == 0:
			output.append(k)
			output.append(n // k)
		k += 1
	return output
numberofcases = int(input())
for _ in range(numberofcases):
	(n, k) = [int(x) for x in input().split()]
	print(n // max([x for x in factors(n) if x <= k]))


for i in range(int(input())):
	(n, k) = [int(num) for num in input().split()]
	factors1 = []
	factors2 = []
	for j in range(1, int(n ** 0.5) + 1):
		if n % j == 0:
			factors1.append(j)
			factors2.append(n // j)
	factors1.reverse()
	factors = factors2 + factors1
	for j in factors:
		if j <= k:
			print(n // j)
			break


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	i = 2
	a = 0
	if k >= n:
		print(1)
		continue
	B = []
	while i * i <= n and i <= k:
		if n % i == 0:
			B.append(i)
			B.append(n // i)
		i += 1
	ans = n
	for i in B:
		if i <= k:
			ans = min(ans, n // i)
	print(ans)


import math

def printDivisors(n, l):
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				l.append(i)
			else:
				l.extend([i, n // i])
		i = i + 1
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	if k >= n:
		print(1)
		continue
	l = []
	printDivisors(n, l)
	l.sort()
	ind = len(l) - 1
	for j in range(len(l)):
		if l[j] > k:
			ind = l[j - 1]
			break
	print(n // ind)


import math
for case in range(int(input())):
	(n, k) = list(map(int, input().split()))
	ans = n
	for i in range(1, min(int(math.sqrt(n)), k) + 1):
		if n % i == 0:
			if n // i <= k:
				ans = i
				break
			ans = n // i
	print(ans)


import math

def Divisors(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
test = int(input())
for i in range(test):
	l = list(map(int, input().split()))
	n = l[0]
	k = l[1]
	if k >= n or n == 1:
		print(1)
	elif k == 1:
		print(n)
	else:
		x = list(Divisors(n))
		x.sort(reverse=True)
		if len(x) > 2:
			for i in x:
				if i <= k:
					print(int(n / i))
					break
		else:
			print(n)


import math
import sys
t = int(input())
for j in range(t):
	(n, k) = map(int, input().split())
	ans = -1
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0 and n // i <= k:
			ans = max(n // i, ans)
		if n % i == 0 and i <= k:
			ans = max(ans, i)
	print(n // ans)


import math
q = int(input())
while q > 0:
	text = input().split(' ')
	n = int(text[0])
	k = int(text[1])
	div = []
	for _ in range(1, math.floor(math.sqrt(n)) + 1):
		if n % _ == 0:
			div.append(_)
			div.append(n / _)
	div = sorted(div)
	for num in div:
		if n / num <= k:
			print(int(num))
			break
	q -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		out = []
		for i in range(int(n ** 0.5) + 1, 0, -1):
			if not n % i:
				out.extend([i, n // i])
		out.sort(reverse=True)
		for i in out:
			if i <= k:
				print(n // i)
				break


def shovels(n, k):
	if n % k == 0:
		print(n // k)
		return
	elif n < k:
		print(1)
		return
	else:
		maximumdivisor = 1
		for i in range(1, int(n ** (1 / 2)) + 1):
			if n % i == 0:
				if i > maximumdivisor and i <= k:
					maximumdivisor = i
				if n // i > maximumdivisor and n // i <= k:
					maximumdivisor = n // i
		print(n // maximumdivisor)
t = int(input())
array = []
for i in range(t):
	array.append(list(map(int, input().split(' '))))
for x in array:
	shovels(*x)


import math
import sys
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	d = 0
	mn = n
	while d * d <= n:
		d += 1
		if n % d == 0:
			d2 = n // d
			if d <= k:
				mn = min(mn, d2)
			if d2 <= k:
				mn = min(mn, d)
	print(mn)


from math import sqrt

def maximum(n, k):
	res = 1
	for i in range(1, int(sqrt(n)) + 2):
		if n % i == 0:
			if i <= k:
				res = max(res, i)
			if n // i <= k:
				res = max(res, n // i)
	return res
for _ in range(int(input())):
	(m, l) = [int(i) for i in input().split()]
	print(m // maximum(m, l))


def findsml(n, k):
	v = n
	m = min(int(pow(n, 0.5)) + 1, k + 1)
	for i in range(1, m):
		if n % i == 0:
			v = min(v, n // i)
			if n // i <= k:
				v = min(v, i)
	return v
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if k >= n:
		print(1)
	else:
		val = findsml(n, k)
		if val == 0:
			print(n)
		else:
			print(val)


import sys
inp = [int(x) for x in sys.stdin.read().split()]
ii = 0
ttt = inp[ii]
ii += 1
res = []
for _ in range(ttt):
	(n, k) = inp[ii:ii + 2]
	ii += 2
	i = 1
	c = 0
	while i <= k and i <= n:
		d = n // (n // i)
		if d <= k and n % d == 0:
			c = d
		i = d + 1
	res.append(n // c)
print('\n'.join((str(x) for x in res)))


from math import sqrt
from sys import maxsize

def solve(n, k):
	upper_bound = min(k, int(sqrt(n)))
	ans = maxsize
	for i in range(1, upper_bound + 1):
		if n % i == 0:
			a = n // i
			if a <= k:
				ans = min(ans, i)
			if i <= k:
				ans = min(ans, a)
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(solve(n, k))


ij = int(input())
for h in range(ij):
	a = 0
	lo = input().split()
	n = int(lo[0])
	k = int(lo[1])
	if k >= n:
		print(1)
	else:
		if int(n / k) == n / k:
			o = int(n / k)
		else:
			o = int(n / k) + 1
		for s in range(o, int(n ** (1 / 2)) + 1):
			if n % s == 0:
				print(int(s))
				a += 1
				break
		if a == 0:
			for z in range(min(k, o), 0, -1):
				if n % z == 0:
					print(int(n / z))
					break


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	sqrt = int(n ** 0.5)
	(each, i) = (1, 1)
	while i <= sqrt:
		(d, m) = divmod(n, i)
		if m == 0 and i <= k:
			each = max(each, i)
			if d <= k:
				each = max(each, d)
		i += 1
	print(n // each)


import math

def largest(n, k):
	i = 1
	c = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if i > c and i <= k:
				c = i
			if n // i > c and n // i <= k:
				c = n // i
		if i > k:
			break
		i = i + 1
	return n // c
t = int(input())
while t != 0:
	t -= 1
	(n, k) = map(int, input().split())
	if n <= k:
		print('1')
	else:
		print(largest(n, k))


from sys import stdin, stdout
import sys
import math
INF = 1000000000.0

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

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

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

def get_string():
	return stdin.readline().strip()

def op(c):
	return stdout.write(c)
for _ in range(int(stdin.readline())):
	(n, k) = get_ints()
	if k >= n:
		print(1)
	else:
		f = 0
		max_d = n
		for i in range(1, int(math.sqrt(n)) + 1):
			if n % i == 0:
				if i <= k:
					max_d = min(max_d, n // i)
				if n // i <= k:
					max_d = min(max_d, i)
		print(max_d)


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(i) for i in st()]
for _ in range(val()):
	(n, k) = li()
	ans = float('inf')
	for j in factors(n):
		if j <= k:
			ans = min(ans, n // j)
		else:
			break
	print(ans)


import math
t = int(input())
while t:
	t = t - 1
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	elif k == 1 or n == 1:
		print(n)
	elif k < n and n % k == 0:
		print(int(n / k))
	else:
		flag = 0
		a = []
		sr = int(math.sqrt(n))
		for w in range(2, int(math.sqrt(n)) + 2):
			if n % w == 0:
				flag = 1
				a.append(int(n / w))
				a.append(w)
		if flag == 0:
			print(n)
		else:
			a = sorted(a)
			a = a[::-1]
			ans = 0
			for w in a:
				if w <= k:
					ans = 1
					print(int(n / w))
					break
			if ans == 0:
				print(n)


import sys, math
input = sys.stdin.readline

def next(arr, target):
	start = 0
	end = len(arr) - 1
	ans = -1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] > target:
			end = mid - 1
		else:
			ans = max(mid, ans)
			start = mid + 1
	return ans

def printDivisors(n):
	d = {}
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				d[i] = 0
			else:
				d[i] = 0
				d[n // i] = 0
		i = i + 1
	return d
t = int(input())
for r in range(t):
	(n, k) = map(int, input().split())
	d = printDivisors(n)
	l = []
	for i in d:
		l.append(i)
	l.sort()
	x = next(l, k)
	print(n // l[x])


INT_MAX = 10 ** 30 + 7
MOD = 10 ** 12 + 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)]
import math as M

def Factors(n):
	A = [1]
	for i in range(2, int(M.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				A.append(i)
			else:
				A.append(i)
				A.append(n // i)
	if len(A) == 1:
		A.append(n)
	A.sort()
	return A

def calc(n, k):
	if k >= n:
		return 1
	F = Factors(n)
	for i in range(len(F)):
		if F[i] <= k:
			ans = F[i]
	return n // ans
for _ in range(int(input())):
	(A, B) = INPUT()
	print(calc(A, B))


import math
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = 1
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0 and i <= k:
			a = max(a, i)
			b = n // i
			if n // i <= k:
				a = max(a, b)
	print(n // a)


from sys import stdin

def factor(a):
	x = []
	y = []
	for i in range(1, int(a ** 0.5) + 1):
		if a % i == 0:
			x.append(i)
			y.append(a // i)
	return x + y
for j in range(int(input())):
	[n, k] = [int(x) for x in stdin.readline().split()]
	t = factor(n)
	t.sort()
	for i in range(len(t)):
		if t[len(t) - 1 - i] <= k:
			print(t[i])
			break


import math

def solve():
	(n, k) = [int(x) for x in input().split()]
	if n <= k:
		print(1)
		return
	else:
		ans = 1
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0 and i <= k:
				ans = max(ans, i)
			if n % (n // i) == 0 and n // i <= k:
				ans = max(ans, n // i)
		print(n // ans)
t = int(input())
for i in range(t):
	solve()


def main():
	(n, m) = list(map(int, input().split()))
	k = 1
	maxi = 0
	while k ** 2 <= n:
		if n % k == 0:
			if k <= m:
				maxi = max(maxi, k)
			if n // k <= m:
				maxi = max(maxi, n // k)
		k += 1
	if maxi == 0:
		print(n)
	else:
		print(n // maxi)
a = int(input())
for i in range(a):
	main()


def main_function():
	from sys import stdin
	from sys import stdout
	from math import sqrt
	from bisect import bisect_right
	input = stdin.readline
	print = stdout.write
	t = int(input())
	for _ in range(t):
		(n, k) = list(map(int, input().split()))
		if k >= n:
			print('1\n')
			continue
		divisors = []
		max_possible_div = int(sqrt(n))
		for num in range(1, max_possible_div + 1):
			if n % num == 0:
				divisors.append(n // num)
				if num * num != n:
					divisors.append(num)
		divisors.sort()
		ans_ix = bisect_right(divisors, k) - 1
		print(f'{n // divisors[ans_ix]}\n')
main_function()


def max_d(n, k):
	ans = 1
	for i in range(1, int(n ** 0.5) + 2):
		if n % i == 0:
			if i <= k:
				ans = max(ans, i)
			if n // i <= k:
				ans = max(ans, n // i)
	return ans
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	print(n // max_d(n, k))


def solve():
	(n, k) = map(int, input().split())
	div = set([])
	for i in range(1, n + 1):
		if i ** 2 > n:
			break
		elif n % i == 0:
			div.add(i)
			div.add(n // i)
	div = list(div)
	div.sort(reverse=True)
	ans = 1
	while div and div[-1] <= k:
		x = div.pop()
		ans = x
	print(n // x)
	return

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


for i in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	d = []
	i = 1
	n1 = n + 0
	while i * i <= n:
		if n % i == 0:
			d += [i, n // i]
		i += 1
	ans = 1
	for i in d:
		if i <= k:
			ans = max(ans, i)
	print(n // ans)


def solve():
	(n, k) = [int(x) for x in input().split()]
	i = 1
	factors = []
	while i * i <= n:
		if n % i == 0:
			factors.append(i)
			factors.append(n // i)
		i += 1
	factors = list(dict.fromkeys(factors))
	factors.sort(reverse=True)
	for val in factors:
		if val <= k:
			return n // val
t = int(input())
while t:
	print(solve())
	t -= 1


from math import sqrt

def mrange(start, stop, step):
	while start < stop:
		yield start
		start += step

def is_prime(num):
	if num == 2:
		return True
	if num < 2 or num % 2 == 0:
		return False
	return all((num % i for i in mrange(3, int(sqrt(num)) + 1, 2)))

def find_t(nk):
	a = nk.split()
	a = list(map(int, a))
	n = a[0]
	k = a[1]
	if n <= k:
		return 1
	elif is_prime(n) or k == 1:
		return n
	elif n % k == 0:
		return n // k
	else:
		factor = []
		for i in range(1, int(sqrt(n) + 1)):
			if n % i == 0:
				factor.append(i)
				factor.append(n // i)
		factor.append(k)
		factor.sort()
		return n // factor[factor.index(k) - 1]
t = int(input())
n_k = []
for i in range(t):
	n_k.append(input())
for i in n_k:
	print(find_t(i))
from math import sqrt


import math

def fun(n):
	ans = []
	for q in range(1, int(math.sqrt(n)) + 1):
		if n % q == 0:
			ans.append(q)
			ans.append(n // q)
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k > n:
		print(1)
	else:
		a = fun(n)
		a.sort(reverse=True)
		for q in a:
			if q <= k:
				print(n // q)
				break


import math
from collections import deque
t = int(input())
rez = []
for i in range(t):
	A = input().split()
	n = int(A[0])
	nn = n
	k = int(A[1])
	if k >= n:
		rez.append(1)
	else:
		for j in range(2, min(k, int(math.sqrt(n))) + 1):
			if n % j == 0 and n / j <= k and (j < nn):
				nn = j
			elif n % j == 0 and n / j > k and (n / j < nn):
				nn = int(n / j)
		rez.append(nn)
for i in range(len(rez)):
	print(rez[i])


for x in range(int(input())):
	(n, k) = map(int, input().split())
	f = 1
	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)))
	a = list(factors(n))
	a.sort()
	for i in range(len(a) - 1, 0, -1):
		if a[i] <= k:
			f = a[i]
			break
	print(n // f)


from math import sqrt, ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	divisors = []
	for i in range(1, ceil(sqrt(n)) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != ceil(sqrt(n)):
				divisors.append(n // i)
	divisors.sort(reverse=True)
	(i, d) = (0, divisors[0])
	while d > k:
		i += 1
		d = divisors[i]
	print(int(n / d))


import sys
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	if n > k:
		ans = 10 ** 18
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				if i <= k:
					ans = min(ans, n // i)
				if n // i <= k:
					ans = min(ans, i)
		if ans == 10 ** 18:
			print(n)
		else:
			print(ans)
	else:
		print(1)


import math

def p(n, k):
	i = 1
	a = []
	while i <= int(math.sqrt(n)):
		if n % i == 0:
			if n // i == i and i <= k:
				(a.append(i),)
			else:
				if i <= k:
					a.append(i)
				if n / i <= k:
					a.append(n // i)
		i = i + 1
	return max(a)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	else:
		print(n // p(n, k))


from math import sqrt
from functools import reduce

def factors(n):
	step = 2 if n % 2 else 1
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(sqrt(n)) + 1, step) if n % i == 0)))
for _ in range(int(input())):
	(n, p) = map(int, input().split())
	lst = list(factors(n))
	lst.sort()
	k = len(lst) - 1
	while k >= 0:
		if lst[k] <= p:
			print(n // lst[k])
			break
		else:
			k -= 1


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	ans = n
	if k >= n:
		print(1)
		continue
	for j in range(1, int(n ** 0.5 + 1)):
		if n % j == 0 and j <= k:
			ans = min(ans, n / j)
			if n / j <= k:
				ans = min(ans, j)
	print(int(ans))


from math import sqrt
t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	if k == 1:
		print(n)
	elif k >= n:
		print(1)
	elif k < n:
		flag = n
		for i in range(2, int(sqrt(n)) + 1):
			if n % i == 0:
				if i <= k and flag > n // i:
					flag = n // i
				if n // i <= k and flag > i:
					flag = i
		print(flag)


T = int(input())
for i in range(0, T):
	(n, k) = list(map(int, input().split()))
	if n <= k:
		print(1)
	else:
		l = int(pow(n, 0.5))
		t = n
		ans = n
		for j in range(2, min(l + 1, k + 1)):
			if n % j == 0:
				x = int(n / j)
				if x < ans:
					ans = x
				y = int(n / x)
				if y < ans and x <= k:
					ans = y
		print(ans)


import math

class Solution:

	def __init__(self):
		(self.n, self.k) = map(int, input().strip().split())
		self.mn = self.n

	def solution(self):
		if self.k >= self.n:
			print(1)
		else:
			for i in range(1, int(math.sqrt(self.n)) + 1):
				if self.n % i == 0:
					if i <= self.k:
						self.mn = min(self.mn, self.n // i)
					if self.n // i <= self.k:
						self.mn = min(self.mn, i)
			print(self.mn)
for _ in range(int(input())):
	ob = Solution()
	ob.solution()


def factors(x):
	result = []
	i = 1
	while i * i <= x:
		if x % i == 0:
			result.append(i)
			if x // i != i:
				result.append(x // i)
		i += 1
	return result
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	mylist = factors(n)
	mylist.sort()
	mylist = mylist[::-1]
	for num in mylist:
		if num <= k:
			print(int(n / num))
			break


import math

def shovels(n, k):
	if n <= k:
		return 1
	if k == 1:
		return n
	m = int(math.sqrt(n)) + 1
	if k < m:
		m = k
	ans = n
	for i in range(2, m + 1):
		if n % i == 0:
			a = i
			b = n // i
			ans = b
			if b <= k:
				return min(a, b)
	return ans
T = int(input())
for i in range(T):
	(n, k) = [int(i) for i in input().split()]
	print(shovels(n, k))


import math

def printDivisors(n):
	l = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				l.append(int(i))
			else:
				l.append(i)
				l.append(int(n / i))
		i = i + 1
	return l
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	if k >= n:
		print(1)
	else:
		l = printDivisors(n)
		l.sort()
		l.reverse()
		for i in range(len(l)):
			if l[i] <= k:
				print(n // l[i])
				break


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	out = n
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i <= k:
				out = min(out, n // i)
			if n // i <= k:
				out = min(out, i)
	print(out)


import math

def findDivisors(n):
	l = list()
	x = int(math.sqrt(n))
	for i in range(1, x + 1):
		if n / i == i:
			l.append(i)
			break
		if n % i == 0:
			l.append(i)
			l.append(n // i)
	l.sort()
	return l
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	elif n % k == 0:
		print(n // k)
	else:
		l = findDivisors(n)
		for i in range(len(l) - 1, -1, -1):
			if l[i] <= k:
				print(n // l[i])
				break


from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	i = 1
	ans = 0
	while i * i <= n:
		if n % i == 0 and i <= k:
			ans = max(ans, i)
			if n // i <= k:
				ans = max(ans, n // i)
		i += 1
	print(n // ans)


import math
t = int(input())
for i in range(t):
	(n, k) = [int(j) for j in input().split()]
	arr = []
	if n <= k:
		print(1)
	else:
		x = int(math.sqrt(n))
		for i in range(1, x + 1):
			if n % i == 0:
				if i <= k:
					arr.append(i)
				if n // i <= k:
					arr.append(n // i)
		print(n // max(arr))


t = int(input())
for i in range(t):
	o = 1
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		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)))
		op = sorted(factors(n))
		for w in op:
			if w <= k:
				o = w
			elif w > k:
				break
		print(n // o)


test = int(input())

def check(t):
	i = 2
	ans = set()
	while i ** 2 <= t:
		if t % i == 0:
			ans.add(i)
			ans.add(n / i)
		i += 1
	if t > 1:
		ans.add(t)
	return ans
for i in range(test):
	(n, k) = [int(i) for i in input().split()]
	if k >= n:
		print(1)
	else:
		flag = 1
		a = [i for i in sorted(check(n), reverse=True)]
		ans = float('inf')
		for i in a:
			if i <= k:
				ans = min(ans, int(n / i))
		if ans != float('inf'):
			print(ans)
		else:
			print(n)


import math
t = int(input())

def p(n, lst, lst2):
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				lst.append(i)
			else:
				lst.append(i)
				lst2.append(n // i)
		i = i + 1
while t:
	(a, b) = map(int, input().split())
	if a <= b:
		print(1)
		t -= 1
		continue
	lst = []
	lst2 = []
	p(a, lst, lst2)
	k = 0
	lst.extend(lst2[::-1])
	for i in lst:
		if i <= b and a % i == 0:
			k = i
			continue
		break
	print(a // k)
	t -= 1


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

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

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		(n, k) = ria()
		z = []
		c = 99999999999999
		for i in range(1, math.floor(math.sqrt(n)) + 1):
			if n % i == 0 and i <= k:
				z.append(i)
				if n // i <= k:
					z.append(n // i)
		print(n // max(z))
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


t = int(input())

def divisors(a):
	i = 1
	b = []
	while i < int(a) ** 0.5 + 2:
		if n % i == 0:
			b.append(i)
			b.append(int(n / i))
		i += 1
	return b

def fun(n, k):
	a = divisors(n)
	a.sort()
	ans = 0
	for i in a:
		if i <= k:
			ans = max(ans, i)
		else:
			break
	print(int(n / ans))
while t:
	t -= 1
	(n, k) = map(int, input().split())
	fun(n, k)


import math
import random

def solve():
	for i in range(1, int(math.ceil(math.sqrt(n))) + 1):
		if n % i == 0:
			if n // i <= k:
				return i
	for i in reversed(range(1, int(math.ceil(math.sqrt(n))) + 1)):
		if n % i == 0:
			if i <= k:
				return n // i
t = int(input())
for i in range(t):
	(n, k) = [int(i) for i in input().split()]
	print(solve())


from math import sqrt

def main():
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		return
	sv = 1
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			if n // i <= k:
				print(i)
				return
			if i <= k:
				sv = max(sv, i)
	print(n // sv)
for t in range(int(input())):
	main()


import sys
input = sys.stdin.readline
from math import *

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

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 k >= n:
		print(1)
	else:
		this = -1
		for i in range(ceil(n ** 0.5), 0, -1):
			if n % i == 0:
				a = i
				b = n // i
				if a <= k:
					this = max(this, a)
				if b <= k:
					this = max(this, b)
		if this == -1:
			print(n)
		else:
			print(n // this)


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 solve():
	for _ in range(ii()):
		(n, k) = mi()
		res = 0
		x = [1, n]
		for i in range(2, int(sqrt(n)) + 1):
			if n % i == 0:
				x.append(i)
				if i != n // i:
					x.append(n // i)
		x.sort()
		c = bisect(x, k) - 1
		if c < 0:
			c = 0
		print(n // x[c])
solve()


def check_factor(n, k):
	li = []
	for i in range(int(n ** (1 / 2)), 0, -1):
		if n % i == 0:
			li.append(i)
			li.append(n // i)
	li.sort(reverse=True)
	for i in range(len(li)):
		if li[i] <= k:
			return li[i]
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = check_factor(n, k)
	print(n // ans)


import math
t = int(input())
for i in range(t):
	b = list(map(int, input().split()))
	n = b[0]
	k = b[1]
	if n <= k:
		print(1)
	else:
		i = 2
		counter = 0
		arr = []
		while i <= int(math.sqrt(n)) and i <= k:
			if n % i == 0:
				counter = 1
				arr.append(i)
			i += 1
		if counter == 0:
			print(n)
		else:
			pointer1 = 0
			for i in range(len(arr)):
				if n // arr[i] <= k:
					print(arr[i])
					pointer1 = 1
					break
			if pointer1 == 0:
				print(n // arr[-1])


for o in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 1
	div = [1, n]
	for i in range(2, int(n ** 0.5 + 1.5)):
		if n % i == 0:
			div += [i, n // i]
	for i in div:
		if i <= k:
			ans = max(i, ans)
	print(n // ans)


def divisor(i):
	s = []
	for j in range(1, int(i ** (1 / 2)) + 1):
		if i % j == 0:
			s.append(i // j)
			s.append(j)
	return sorted(set(s))
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	s = divisor(n)
	s.reverse()
	for i in s:
		if i <= k:
			print(n // i)
			break


abba = int(input())
for u in range(abba):
	(n, k) = map(int, input().split())
	l = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			(x, y) = (i, n // i)
			if x <= k:
				l.append(x)
			if y <= k:
				l.append(y)
	d = max(l)
	print(n // d)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	elif k == 1:
		print(n)
	else:
		q = False
		m = -1
		for i in range(2, min(k + 1, int(n ** 0.5) + 2)):
			if n % i == 0:
				if n // i > k:
					q = True
					m = n // i
					st = i
				else:
					f = True
					print(i)
					break
		else:
			if m != -1:
				print(m)
			else:
				print(n)


t = input()
t = int(t)
shetchikshetchikov1 = 0
while shetchikshetchikov1 < t:
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	shetchik123 = 1
	a = []
	if k >= n:
		print('1')
	else:
		while shetchik123 * shetchik123 <= n and shetchik123 <= k:
			if n % shetchik123 == 0:
				if n // shetchik123 <= k:
					print(shetchik123)
					break
				else:
					a.append(shetchik123)
			shetchik123 = shetchik123 + 1
		else:
			if len(a) > 1:
				print(n // a[len(a) - 1])
			else:
				print(n)
	shetchikshetchikov1 = shetchikshetchikov1 + 1


import math

def factors(n):
	t = int(math.sqrt(n))
	ans = 0
	for i in range(2, t + 1):
		if n % i == 0:
			if n // i != i and n // i <= k:
				ans = n // i
				break
			elif i <= k:
				ans = i
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		ans = n
	else:
		ans = factors(n)
		if ans == 0:
			ans = 1
	print(n // ans)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
cases = int(input())
for t in range(cases):
	(n, k) = list(map(int, input().split()))
	if n <= k:
		print(1)
	else:
		f = 1
		v = min(k, int(n ** 0.5))
		for i in range(1, v + 1):
			if n % i == 0:
				f = max(f, i)
				if n // i <= k:
					f = max(f, n // i)
		print(n // f)


import math, sys, bisect
from collections import defaultdict, Counter, deque

def input():
	return sys.stdin.readline().strip()
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

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())):
	(a, b) = ilele()
	if b >= a:
		print(1)
	else:
		A = printDivisors(a)
		A.sort(reverse=True)
		for i in A:
			if i <= b:
				print(a // i)
				break


import math as ma
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	num = n
	for i in range(1, int(ma.sqrt(n)) + 1):
		if n % i == 0:
			if i <= m:
				num = min(num, n // i)
			if n // i <= m:
				num = min(num, i)
	print(num)


import math

def smallestfactors(n, k):
	ans = n
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n // i <= k:
				return i
			if i <= k:
				ans = min(ans, n // i)
	return ans
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	print(smallestfactors(n, k))


t = int(input())
cnt = 0
while cnt < t:
	cnt += 1
	(n, k) = [int(i) for i in input().split()]
	prime_lst = list(range(1, min(int(n ** 0.5) + 1, k + 1)))
	if n <= k:
		print(1)
	else:
		base = n
		tmp = n
		for i in prime_lst:
			if n % i == 0:
				tmp = n // i
				if n // i <= k:
					base = i
					break
		print(min(base, tmp))


import sys
import math
from math import sqrt
from functools import reduce
from sys import stdin, stdout

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 factors(n):
	step = 2 if n % 2 else 1
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(sqrt(n)) + 1, step) if n % i == 0)))
for _ in range(int(stdin.readline())):
	(n, k) = list(map(int, stdin.readline().split()))
	isit = isPrime(n)
	if k >= n:
		print(1)
	elif isit == True:
		print(n)
	else:
		x = list(factors(n))
		x.sort()
		for i in range(len(x)):
			if x[i] > k:
				ans = x[i - 1]
				break
		print(n // ans)


from math import *
from sys import *
input = stdin.buffer.readline
for u in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		m = n
		for i in range(2, int(min(k, sqrt(n))) + 1):
			if n % i == 0:
				m = min(m, n // i)
				if n // i <= k:
					m = min(m, i)
		print(m)


from sys import stdin
for _ in range(int(input())):
	(n, k) = map(int, stdin.readline().split())
	factors = [1]
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			factors += (i,)
			factors += (n // i,)
	factors.sort()
	factors.reverse()
	for i in factors:
		if i <= k:
			print(n // i)
			break


def check(num, k):
	rec = []
	n = int(num ** 0.5 // 1)
	for i in range(1, n + 1):
		if num % i == 0:
			temp = num // i
		else:
			continue
		if i <= k:
			rec.append(i)
		if temp <= k:
			rec.append(temp)
	rec.sort()
	return rec[-1]
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		gcd = check(n, k)
		print(int(n // gcd))


import math
t = int(input())
for tc in range(t):
	(n, k) = [int(_) for _ in input().split()]
	D = set()
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			D.add(i)
			D.add(n / i)
		i += 1
	d = max([d for d in D if d <= k])
	print(int(n // d))


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	if k >= n:
		print(1)
	else:
		best = 99999999999999
		for j in range(1, int(n ** 0.5) + 1):
			if j <= k and n % j == 0:
				if n // j < best:
					best = n // j
				if j < best and n // j <= k:
					best = j
		print(best)


from math import sqrt

def dhana(a, b):
	ans = a
	x = int(sqrt(a))
	for i in range(1, x + 1):
		if a % i == 0:
			if i <= b:
				ans = min(ans, a // i)
			if a // i <= b:
				ans = min(ans, i)
	return ans
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	c = dhana(a, b)
	print(c)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	elif k == 1:
		print(n)
	elif n % 2 == 0 and n // 2 <= k:
		print(2)
	else:
		l = int(math.sqrt(n)) + 1
		ans = n
		for i in range(2, l + 1):
			if n % i == 0:
				if i <= k:
					ans = min(ans, n // i)
				if n // i <= k:
					ans = min(ans, i)
		print(ans)


def prime_factorization(n):
	factors = [1]
	while n % 2 == 0:
		factors.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n = n // i
	if n > 2:
		factors.append(n)
	return factors

def d(factors, n, k):
	factor_candidates = [1]
	for f in factors:
		for i in range(len(factor_candidates)):
			ffc = f * factor_candidates[i]
			if ffc <= k:
				factor_candidates.append(ffc)
	return n // max(factor_candidates)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	factors = prime_factorization(n)
	if k >= n // factors[1]:
		print(factors[1])
	else:
		print(d(factors, n, k))


import sys
import math
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
for t in range(int(input())):
	(n, k) = intInp()
	if k >= n:
		print(1)
	else:
		m = 1
		for i in range(2, min(k + 1, 31623)):
			if n % i == 0:
				m = max(i, m)
				if n // i <= k:
					m = max(m, n // i)
		if m == 1:
			print(n)
		else:
			print(n // m)


import math
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	if k >= n:
		print(1)
	else:
		ans = math.inf
		for i in range(1, int(math.sqrt(n)) + 1):
			if n % i == 0:
				if i <= k:
					ans = min(ans, n // i)
				if n // i <= k:
					ans = min(ans, i)
		print(ans)


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	(c, d) = (1, 0)
	while c * c <= a and c <= b:
		if a % c == 0:
			if a // c <= b:
				d = a // c
				break
			else:
				d = c
		c += 1
	print(a // d)


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
import math

def get_large(n, k):
	ans = n
	for d in range(2, min(k, math.ceil(math.sqrt(n))) + 1):
		if n % d == 0:
			ans = n // d
			if ans <= k:
				return d
	return ans

def four(n, k):
	if k >= n:
		return 1
	if isPrime(n):
		return n
	return get_large(n, k)
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(four(n, k))


from math import sqrt
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 1
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0 and i <= k:
			ans = max(i, ans)
			d = n // i
			if n % d == 0 and d <= k:
				ans = max(ans, d)
	print(n // ans)


def get_it(n, k):
	if n % k == 0:
		return n // k
	upper_bound = min(k, int(n ** 0.5))
	M = 0
	for i in range(1, upper_bound + 1):
		if n % i == 0:
			M = i
			if n // i < k:
				return i
	return n // M

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


for i in range(int(input())):
	(n, k) = map(int, input().split())
	_any = int(n ** 0.5) + 1
	min_ = 0
	max_ = 0
	for j in range(_any, 0, -1):
		if not n % j:
			if not min_ and j <= k:
				min_ = j
			if n // j <= k:
				max_ = n // j
	print(n // max(min_, max_))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	c = n
	if k >= n:
		print(1)
	else:
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0 and i <= k:
				if n // i <= k:
					c = min(c, i)
				else:
					c = min(c, n // i)
			elif i > k:
				break
		print(c)


import math

def function(n, k):
	if n <= k:
		return 1
	result = 10 ** 9
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i <= k:
				result = min(result, n / i)
			if n / i <= k:
				result = min(result, i)
	return int(result)
t = int(input())
for j in range(t):
	l1 = list(map(int, input().rstrip().split()))
	n = l1[0]
	k = l1[1]
	print(function(n, k))


import math

def lf(rb, lb):
	i = 1
	ans = rb
	while i ** 2 <= rb:
		if rb % i == 0:
			if i <= k:
				ans = min(ans, rb // i)
			if rb // i <= k:
				ans = min(ans, i)
		i += 1
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n == k:
		print(1)
	else:
		print(lf(n, k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	f = []
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				if i <= k:
					f.append(i)
				if int(n / i) <= k:
					f.append(int(n / i))
		print(int(n / max(f)))


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from bisect import bisect_left, bisect, bisect_right
from functools import reduce
import math

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 all_factors(n):
	return list(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def solve():
	(n, k) = get_tuple()
	if n < k:
		print(1)
	else:
		factors = all_factors(n)
		factors.sort()
		ans = 1
		for val in factors:
			if val <= k:
				ans = val
			else:
				break
		print(math.ceil(n / ans))

def main():
	solve()
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


import math
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	ans = 1
	for i in range(1, int(math.sqrt(a)) + 1):
		if a % i == 0 and i <= b:
			ans = max(ans, i)
			div = a // i
			if a // i <= b:
				ans = max(ans, div)
	print(a // ans)


import math
t = int(input())
while t > 0:
	t -= 1
	(a, b) = map(int, input().split())
	if a <= b:
		print(1)
		continue
	ans = 9999999999
	for i in range(1, min(b, int(math.sqrt(a) + 1)) + 1):
		if a % i == 0:
			if a // i <= b:
				ans = min(ans, i)
			else:
				ans = min(ans, a // i)
	print(ans)


def divisor(n):
	A = []
	for i in range(1, int(n ** (1 / 2) + 1)):
		if n % i == 0 and n / i != i:
			A.append(i)
			A.append(n // i)
		elif n / i == i:
			A.append(i)
	return A

def up(n, k):
	R = divisor(n)
	C = []
	for i in range(len(R)):
		if R[i] <= k:
			C.append(R[i])
	return n // max(C)
t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	print(up(n, k))
	t -= 1


import math

def div(n):
	i = 1
	ans = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				ans.append(i)
			else:
				ans.append(i)
				ans.append(int(n / i))
		i = i + 1
	return ans
t = int(input())
for g in range(0, t):
	nk = list(map(int, input().split()))
	n = nk[0]
	k = nk[1]
	if k >= n:
		print(1)
	else:
		divisors = div(n)
		divisors.sort()
		for i in range(len(divisors) - 1, -1, -1):
			if divisors[i] <= k:
				print(int(n / divisors[i]))
				break


def divisors(n):
	factors = {}
	nn = n
	i = 2
	while i * i <= nn:
		while nn % i == 0:
			factors[i] = factors.get(i, 0) + 1
			nn //= i
		i += 1
	if nn > 1:
		factors[nn] = factors.get(nn, 0) + 1
	primes = list(factors.keys())

	def generate(k):
		if k == len(primes):
			yield 1
		else:
			rest = generate(k + 1)
			prime = primes[k]
			for factor in rest:
				prime_to_i = 1
				for _ in range(factors[prime] + 1):
					yield (factor * prime_to_i)
					prime_to_i *= prime
	for factor in generate(0):
		yield factor
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	l = n
	ma = 0
	if k >= n:
		print('1')
	else:
		v = 1
		lst = list(divisors(n))
		lst = sorted(lst)
		for p in range(len(lst)):
			if lst[p] > k:
				v = p
				break
		print(int(l / lst[v - 1]))


import math
test = int(input())
while test > 0:
	test -= 1
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		rs = n
		for i in range(2, min(k + 1, int(math.sqrt(n)) + 1)):
			if n % i == 0:
				if n // i <= k:
					rs = i
					break
				rs = min(rs, n // i)
		print(rs)


from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict
import math
rl = lambda : stdin.readline()
rll = lambda : stdin.readline().split()
rli = lambda : map(int, stdin.readline().split())
(INF, NINF) = (float('inf'), float('-inf'))

def main():
	T = int(rl())
	for _ in range(T):
		(n, k) = rli()
		k = min(k, n)
		i = 1
		if k >= n:
			print('1')
			continue
		ans = INF
		while i <= math.ceil(math.sqrt(n)) and i <= k:
			if n % i == 0:
				ans = min(ans, n // i)
				if n // i <= k:
					ans = min(ans, n // (n // i))
			i += 1
		print(ans)
	stdout.close()
main()


R1 = lambda : list(map(int, input().split()))
R2 = lambda : int(input())
for _ in range(R2()):
	(n, k) = R1()
	r = 1
	res = n
	while r * r <= n:
		if n % r == 0:
			if r <= k:
				res = min(res, n // r)
			if n // r <= k:
				res = min(res, r)
		r += 1
	print(res)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	sqrt = int(math.sqrt(n))
	(val, i) = (1, 1)
	while i <= sqrt:
		if n % i == 0 and i <= k:
			val = max(val, i)
			if n // i <= k:
				val = max(val, n // i)
		i += 1
	print(n // val)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif n % k == 0:
		print(n // k)
	else:
		res = n
		t = int(pow(n, 0.5))
		for t in range(1, t + 1):
			if n % t == 0:
				if t <= k:
					res = min(res, n // t)
				if n // t <= k:
					res = min(res, t)
		print(res)


import sys
import math as m
t = int(input())
while t > 0:
	t = t - 1
	ans = sys.maxsize * 1
	(n, k) = map(int, input().split())
	if k >= n:
		print('1')
	else:
		x = min(k + 1, m.ceil(m.sqrt(n)) + 1)
		for i in range(1, x):
			if n % i == 0:
				ans1 = n // i
				if n // i <= k:
					ans1 = i
				ans = min(ans, ans1)
		print(ans)


test = int(input())
while test != 0:
	(n, k) = [int(x) for x in input().split()]
	if n <= k:
		print(1)
	elif k == 1:
		print(n)
	else:
		x = int(n ** 0.5)
		x += 5
		if k < x:
			x = k
		numm = 1
		for i in range(x, 1, -1):
			if n % i == 0:
				numm = max(numm, i)
				if n / i <= k:
					numm = max(numm, n / i)
		print(int(n / numm))
	test -= 1


import math
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)))

def is_prime(n):
	if n <= 1:
		return False
	max_div = math.floor(math.sqrt(n))
	for i in range(2, 1 + max_div):
		if n % i == 0:
			return False
	return True
x = int(input())
for i in range(x):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	elif is_prime(n) == True:
		print(n)
	else:
		q = list(factors(n))
		q.sort()
		i = 0
		while q[i] <= k:
			i += 1
		print(n // q[i - 1])


import sys
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = int(1000000000.0)
	for i in range(1, n + 1):
		if i * i > n:
			break
		if n % i == 0:
			if i <= k:
				ans = min(ans, n // i)
			if n / i <= k:
				ans = min(ans, n // (n // i))
	print(ans)


def solve(buy, packages):
	ans = 0
	root = int(buy ** 0.5 + 0.5)
	for x in range(1, root + 1):
		if buy % x == 0:
			if buy // x <= packages:
				return x
			if x <= packages:
				ans = buy // x
	return ans
for x in range(int(input())):
	(b, p) = list(map(int, input().split()))
	print(solve(b, p))


from math import sqrt
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	d = 1000000000 + 1
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0 and n // i <= k:
			d = i
			break
		elif n % i == 0 and i <= k:
			d = min(n // i, d)
	if d == 1000000000 + 1:
		print(n)
	else:
		print(d)


t = int(input())
for gf in range(t):
	(n, k) = [int(x) for x in input().split()]
	q = int(n ** 0.5)
	if k >= n:
		print(1)
	else:
		res = 0
		s = 1
		for i in range(1, q + 1):
			if n % i == 0 and i <= k:
				s = max(i, s)
			if n % i == 0 and n // i <= k:
				s = max(n // i, s)
			res = max(s, res)
		print(n // res)


import os
import sys
from io import BytesIO, IOBase
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 main():
	try:
		from math import floor, ceil
		for _ in range(inp()):
			(n, k) = invr()
			ans = n
			for x in range(1, ceil(n ** 0.5) + 1):
				if n % x == 0:
					if x <= k:
						ans = min(ans, n // x)
					if n // x <= k:
						ans = min(ans, x)
			print(ans)
	except Exception as e:
		print(e)
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')
main()


for q in range(int(input())):
	(n, k) = map(int, input().split())
	flag = 0
	if n <= k:
		print(1)
	elif k == 1:
		print(n)
	else:
		arr = []
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				flag = 1
				arr.append(i)
				arr.append(n // i)
		if flag == 0:
			print(n)
		else:
			arr.sort()
			for i in range(len(arr) - 1, -1, -1):
				if arr[i] <= k:
					print(n // arr[i])
					break


for xyz in range(0, int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		m = 1
		root = int(n ** 0.5)
		for i in range(1, min(k + 1, root + 1)):
			if n % i == 0:
				if i <= k:
					if i > m:
						m = i
				if n // i <= k:
					if n // i > m:
						m = n // i
		print(n // m)


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split(' '))
	if k >= n:
		print('1')
	elif k == 1:
		print(n)
	else:
		if k < math.sqrt(n):
			v = k
		else:
			v = int(math.sqrt(n))
		c1 = 0
		l = []
		for z in range(2, v + 1):
			if n % z == 0:
				nv = int(n / z)
				l.append(z)
				if nv <= k:
					a = z
					c1 = 1
					break
		if c1 == 1:
			print(a)
		elif not l:
			print(n)
		else:
			l.sort(reverse=True)
			for ele in l:
				if ele <= k:
					print(int(n / ele))
					break


from math import sqrt
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	z = float('-inf')
	for j in range(1, min(int(sqrt(n) + 1), k + 1)):
		if n % j == 0:
			z = max(z, j)
		if n // j <= k and n % j == 0:
			z = max(z, n // j)
	print(n // z)


import sys
import math
input = sys.stdin.readline

def ini():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])
t = ini()
for i in range(t):
	nk = inli()
	n = nk[0]
	k = nk[1]
	if k >= n:
		print(1)
	else:
		best = n
		for j in range(1, math.floor(math.sqrt(n)) + 1):
			if n % j == 0:
				f = int(n / j)
				if j <= k:
					best = min(best, f)
				if f <= k:
					best = min(best, j)
		print(best)


import math
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		Max = 10000000000
		for i in range(1, int(math.sqrt(n)) + 1):
			if n % i == 0:
				if i <= k:
					Max = min(Max, n // i)
				if n // i <= k:
					Max = min(Max, i)
		print(Max)


from sys import stdin, stdout
import math
import bisect

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

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

def getDivisors(n):
	l1 = []
	l2 = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			l1.append(i)
			if n / i != i:
				l2.append(int(n / i))
	for i in l2[::-1]:
		l1.append(i)
	return l1
t = II()
for _ in range(t):
	(n, k) = MI()
	l = getDivisors(n)
	if k >= n:
		ans = 1
	else:
		idx = bisect.bisect_left(l, k)
		if l[idx] == k:
			ans = n // k
		else:
			ans = n // l[idx - 1]
	stdout.write(str(ans) + '\n')


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

def solve():
	(n, k) = [int(x) for x in input().split()]
	divs = [1, n]
	d = 2
	while d * d <= n:
		if n % d == 0:
			divs.append(d)
			divs.append(n // d)
		d += 1
	divs.sort(reverse=True)
	for el in divs:
		if el <= k:
			print(n // el)
			return
tt = int(input())
for test in range(tt):
	solve()


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	(n, k) = zz()
	m = 1
	for i in range(1, ceil(n ** 0.5) + 1):
		if n % i == 0:
			t = n // i
			if t <= k and n % t == 0:
				m = max(m, t)
			if i <= k:
				m = max(m, i)
	print(n // m)


from sys import stdin, stdout
import math
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	if k >= n:
		print(1)
		continue
	found = False
	ans = n
	for i in range(min(k, int(math.sqrt(n) + 1)), 1, -1):
		if n % i == 0:
			ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
	print(ans)


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 primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

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
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

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 solve():
	(n, k) = num_input()
	if k >= n:
		print(1)
	else:
		factors = getFactors(n)
		factors.sort(reverse=True)
		for i in factors:
			if i <= k:
				print(n // i)
				return
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	factors = []
	i = 1
	while i * i <= a:
		if a % i == 0:
			factors.append(i)
			factors.append(a // i)
		i += 1
	factors.append(a)
	ans = 0
	for i in factors:
		if i <= b:
			ans = max(ans, i)
	print(a // ans)


t = int(input())

def printDivisors(n):
	div = []
	i = 1
	while i <= int(n ** 0.5):
		if n % i == 0:
			if n / i == i:
				div.append(i)
			else:
				div.append(i)
				div.append(n // i)
		i = i + 1
	return div
for _ in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
		continue
	satisfies = printDivisors(n)
	ans = float('inf')
	for val in satisfies:
		if val <= k:
			ans = min(ans, n // val)
	print(ans)


import math
t = int(input())
while t > 0:
	flag = 0
	m = 1
	(n, k) = map(int, input().split())
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i <= k and i > m:
				m = i
			if n // i <= k and n // i > m:
				m = n // i
	print(n // m)
	t -= 1


import math

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


cases = int(input())
for i in range(cases):
	l1 = input().split(' ')
	n = int(l1[0])
	k = int(l1[1])
	ans = n
	for j in range(int(n ** 0.5), 0, -1):
		if n % j == 0:
			if j <= k:
				ans = min(ans, int(n / j))
			if n / j <= k:
				ans = min(ans, j)
	print(ans)


import math
m = int(input())
for i in range(m):
	(n, k) = list(map(int, input().split()))
	flag = False
	i = 1
	pos = 0
	while i * i <= n:
		if n % i == 0:
			if n / i <= k:
				print(i)
				flag = True
				break
			elif i <= k:
				pos = n // i
		i += 1
	if not flag:
		if pos > 0:
			print(pos)
		else:
			print(n)


import math
el = int(input())
for j in range(el):
	ar = []
	for i in input().split():
		ar.append(int(i))
	i = 1
	divisors = []
	while i <= math.sqrt(ar[0]):
		if ar[0] % i == 0:
			if ar[0] / i == i:
				divisors.append(i)
			else:
				divisors.append(i)
				divisors.append(int(ar[0] / i))
		i = i + 1
	res = ar[0]
	for i in divisors:
		if i > ar[1]:
			continue
		if ar[0] / i < res:
			res = ar[0] / i
	print(int(res))


t = int(input())
while t:
	(n, k) = map(int, input().split())
	div1 = []
	div2 = []
	i = 1
	while i * i <= n:
		if n % i == 0:
			div1.append(i)
			div2.append(int(n / i))
		i += 1
	div = div1 + div2[::-1]
	for i in range(len(div) - 1, -1, -1):
		if div[i] > k:
			continue
		elif div[i] <= k:
			print(int(n / div[i]))
			break
	t -= 1


import sys
for line in sys.stdin:
	if ' ' in line:
		(n, p) = tuple(map(int, line.split()))
		answer = n
		divisor = 1
		while divisor ** 2 <= n and divisor <= p:
			if n % divisor == 0:
				if n // divisor <= p:
					answer = divisor
					break
				answer = min(n // divisor, answer)
			divisor += 1
		print(answer)


import math
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	f = []
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n // i == i:
				f.append(i)
			else:
				f.append(i)
				f.append(n // i)
	f.sort()
	for i in f:
		if n // i <= k:
			print(i)
			break


for _ in range(0, int(input())):
	(n, k) = map(int, input().split())
	divisors = []
	i = 1
	while i * i <= n:
		if n % i == 0:
			divisors.append(i)
		i += 1
	max = 1
	for j in divisors:
		if j <= k and j > max:
			max = j
		if round(n / j) <= k and round(n / j) > max:
			max = round(n / j)
	print(round(n / max))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	gd = 1
	if k >= n:
		gd = n
		print(n // gd)
	elif k == 1:
		gd = 1
		print(n // gd)
	else:
		i = 2
		while i * i <= n:
			if n % i == 0:
				if i <= k:
					gd = max(gd, i)
				if n // i <= k:
					gd = max(gd, n // i)
			i += 1
		print(int(n / gd))


t = int(input())
answer = []
for kek in range(t):
	(n, k) = map(int, input().split())
	ans = 10 ** 10
	for i in range(1, min(k + 1, int(n ** (1 / 2) + 2))):
		if n % i == 0:
			if n // i <= k:
				ans = min(ans, i)
			if i <= k:
				ans = min(ans, n // i)
	answer.append(ans)
print(*answer, sep='\n')


import math

def helper(n):
	i = 1
	arr = []
	arr.append(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 tes in range(t):
	(a, b) = map(int, input().split())
	if b >= a:
		print(1)
		continue
	arr = helper(a)
	arr.sort()
	ans = 99999999999999999
	for i in range(len(arr)):
		if arr[i] <= b:
			ans = min(ans, a / arr[i])
	print(int(ans))


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

def max_div(k, n):
	ans = n
	for j in range(1, int(n ** (1 / 2)) + 1):
		if n % j == 0:
			if j <= k:
				ans = min(ans, n / j)
			if n / j <= k:
				ans = min(ans, j)
	return ans
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(int(max_div(k, n)))


import math
for i in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n
	if n <= k:
		print(1)
	else:
		for j in range(1, int(math.sqrt(n)) + 1):
			if n % j == 0:
				if j <= k:
					ans = min(ans, n // j)
				if n // j <= k:
					ans = min(ans, j)
		print(ans)


for ad in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		t = 0
		l = []
		for i in range(2, int(n ** 0.5) + 3):
			if n % i == 0:
				if n // i <= k:
					print(i)
					t = 1
					break
				elif i <= k:
					l.append(n // i)
		if t == 0:
			if len(l) == 0:
				print(n)
			else:
				print(min(l))


t = int(input())
for x in range(t):
	(n, k) = map(int, input().split())
	if k == 1:
		print(n)
	elif n == k:
		print(1)
	elif k > n:
		print(1)
	else:
		g_min = []
		if k >= n // 2 and n % 2 == 0:
			print(2)
		else:
			i = 1
			while i <= int(n ** 0.5) and i <= k:
				if n % i == 0:
					d1 = i
					d2 = n // i
					g_min.append(d1)
					g_min.append(d2)
				i += 1
			g_min.sort()
			z = len(g_min) - 1
			while z >= 0:
				if n % g_min[z] == 0 and g_min[z] <= k:
					print(n // g_min[z])
					break
				z -= 1


import sys
import math

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

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

def ILS():
	return list(map(str, sys.stdin.readline().strip().split()))
pr = [1]

def SieveOfEratosthenes(n):
	global pr
	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]:
			pr.append(p)
t = I()
SieveOfEratosthenes(100000)
for i in range(t):
	(n, k) = IL()
	ans = n
	sq = int(math.sqrt(n))
	for pp in range(1, sq + 1):
		if n % pp == 0:
			if n // pp <= k:
				ans = min(pp, ans)
			if pp <= k:
				ans = min(n // pp, ans)
	print(ans)


import sys
import math
from sys import stdin, stdout

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

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

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

def main():
	for t in range(int(input())):
		(n, k) = get_ints()
		if k >= n:
			print(1)
		else:
			l = []
			s = int(n ** 0.5) + 1
			for i in range(1, s + 1):
				if n % i == 0:
					if n // i == i:
						l.append(i)
					else:
						l.append(n // i)
						l.append(i)
			l.sort()
			for i in range(len(l)):
				if n // l[i] <= k:
					print(l[i])
					break
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
main()


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print('1')
	else:
		a = []
		for i in range(int(n ** 0.5), 0, -1):
			if n % i == 0:
				div = i
				q = n // i
				if max(div, q) <= k:
					a.append(n // max(div, q))
				elif min(div, q) <= k:
					a.append(n // min(div, q))
		print(min(a))


import math
an = []
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		an.append(1)
	else:
		v = []
		l = math.sqrt(n) + 1
		j = 2
		while j <= min(l, k):
			if n % j == 0:
				v.append(j)
				c = n // j
				j = j + 1
				if c <= k:
					v.append(c)
					j = k
			else:
				j = j + 1
		if v == []:
			an.append(n)
		else:
			an.append(n // v[-1])
for i in range(0, t):
	print(an[i])


import math

def printDivisors(n, m):
	i = 1
	s = 9999999999
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				if i <= m:
					s = min(s, n // i)
			else:
				if i <= m:
					s = min(s, n // i)
				if n // i <= m:
					s = min(s, n // (n // i))
		i = i + 1
	return s
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	k = printDivisors(n, m)
	print(k)


import math, sys
(input, print) = (sys.stdin.readline, sys.stdout.write)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n
	for el in range(1, int(math.sqrt(n)) + 1):
		if n % el == 0:
			if n // el <= k:
				ans = min(ans, el)
			if el <= k:
				ans = min(ans, n // el)
	print(str(ans) + '\n')


import sys

def main():
	res = ''
	input = sys.stdin.readline
	print = sys.stdout.write
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		i = 1
		sn = n ** 0.5
		max_d = 1
		while i < sn + 1 and i <= k:
			if n % i == 0:
				a = n // i
				if a <= k:
					max_d = a
					break
				else:
					max_d = i
			i += 1
		sub_res = str(n // max_d)
		res += sub_res + '\n'
	print(res)
main()


from math import sqrt
for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	maxDiv = 1
	if k < sqrt(n):
		lim = k + 1
	else:
		lim = int(sqrt(n) + 1)
	for i in range(1, lim):
		if n % i == 0:
			if n // i <= k:
				maxDiv = n // i
				break
			else:
				maxDiv = i
	print(n // maxDiv)


import bisect
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	f = [1, n]
	j = 2
	while j * j < n:
		if n % j == 0:
			f += [j, n // j]
		j += 1
	if j * j == n:
		f.append(j)
	f.sort()
	x = bisect.bisect_right(f, k)
	print(n // f[x - 1])


import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
	T = int(input())
	for _ in range(T):
		(N, K) = map(int, input().split())
		ans = INF
		for i in range(1, N + 1):
			if i * i > N:
				break
			if N % i == 0:
				if i <= K:
					ans = min(ans, N // i)
				if N <= K * i:
					ans = min(ans, i)
		print(ans)
main()


import math
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())
while t > 0:
	(n, k) = [int(x) for x in input().split()]
	if n < k or n == k:
		print(1)
	else:
		a = factors(n)
		a = list(a)
		a.sort(reverse=True)
		a.pop(0)
		for i in a:
			if i <= k:
				print(int(n / i))
				break
	t = t - 1


from sys import stdin, stdout

def input():
	return stdin.readline()

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif isprime(n):
		print(n)
	else:
		l = []
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				l.append(i)
				l.append(n // i)
		l.sort(reverse=True)
		for i in l:
			if i <= k:
				m = i
				break
		print(n // i)


t = int(input())
res = []
for i in range(t):
	inp = input()
	arr = list(map(int, inp.split()))
	n = arr[0]
	k = arr[1]
	if k >= n:
		res.append(1)
	else:
		m = int(n ** 0.5) + 1
		p = True
		l = []
		for i in range(m, 0, -1):
			if n % i == 0:
				p = False
				a = i
				b = n // a
				if b <= k:
					l.append(a)
				elif a <= k:
					l.append(b)
		res.append(min(l))
for i in res:
	print(i)


import math

def factors(n, k):
	sqrtn = math.ceil(math.sqrt(n))
	maxi = n
	q = n
	for i in range(2, sqrtn + 1):
		if n % i == 0:
			if i == k:
				return n // i
			elif i > k:
				return q
			q = n // i
			maxi = i
			if q <= k:
				return i
		if i >= k:
			return q
	return q
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k == 1:
		print(n)
	elif k >= n:
		print(1)
	else:
		print(factors(n, k))


def primes(x, d):
	ret_list = [1]
	i = 2
	j = n // 2
	while i <= j:
		if n % i == 0:
			if i <= k:
				ret_list.append(i)
			if n // i <= k:
				ret_list.append(n // i)
		i += 1
		j = n // i
	return ret_list
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	if k >= n:
		print(1)
		continue
	elif k == 1:
		print(n)
		continue
	else:
		p = primes(n, k)
		print(n // max(p))


import math
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	res = n
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n // i <= k and i <= res:
				res = i
			elif i <= k and n // i <= res:
				res = n // i
	print(res)


import math
for t in range(int(input())):
	(n, k) = map(int, input().split())
	d = 1
	if k >= n:
		print('1')
	elif n % k == 0:
		print(n // k)
	else:
		for q in range(2, min(k, int(math.sqrt(n))) + 1):
			if n % q == 0:
				d = q
				if n // q <= k:
					print(q)
					break
		else:
			print(n // d)


import math
import sys
author = 'DarshanMohan'

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():
	return list(MAP())

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def add(a, b, c):
	res = a + b
	if res >= c:
		return res - c
	else:
		return res

def mod(a, b, c):
	res = a * b
	if res >= c:
		return res % c
	else:
		return res

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

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

def printDivisors(n):
	list = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				list.append(i)
			else:
				list.append(i)
				list.append(int(n / i))
	return list
for _ in range(INT()):
	(n, k) = MAP()
	divs = printDivisors(n)
	divs.sort()
	if n <= k:
		print(1)
	elif k == 1:
		print(n)
	else:
		temp = 0
		for i in range(len(divs)):
			if divs[i] <= k:
				temp = divs[i]
		print(n // temp)


import sys
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right
from collections import deque
from collections import Counter
from itertools import accumulate, combinations, permutations
from heapq import heapify, heappop, heappush
from functools import lru_cache

def input():
	return sys.stdin.readline()[:-1]

def printl(li):
	_ = print(*li, sep='\n') if li else None

def argsort(s, return_sorted=False):
	inds = sorted(range(len(s)), key=lambda k: s[k])
	if return_sorted:
		return (inds, [s[i] for i in inds])
	return inds

def alp2num(c, cap=False):
	return ord(c) - 97 if not cap else ord(c) - 65

def num2alp(i, cap=False):
	return chr(i + 97) if not cap else chr(i + 65)

def matmat(A, B):
	(K, N, M) = (len(B), len(A), len(B[0]))
	return [[sum([A[i][k] * B[k][j] for k in range(K)]) for j in range(M)] for i in range(N)]

def matvec(M, v):
	(N, size) = (len(v), len(M))
	return [sum([M[i][j] * v[j] for j in range(N)]) for i in range(size)]

def T(M):
	(n, m) = (len(M), len(M[0]))
	return [[M[j][i] for j in range(n)] for i in range(m)]

def main():
	mod = 1000000007
	(N, K) = map(int, input().split())
	if K >= N:
		print(1)
		return
	n = 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()
	print(N // divisors[bisect_right(divisors, K) - 1])
q = int(input())
for _ in range(q):
	main()


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 solve():
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if k >= n:
		print(1)
	elif n % 2 == 0 and n // 2 <= k:
		print(2)
	else:
		ans = []
		i = 2
		temp = n
		while i * i <= n:
			if n % i == 0:
				ans.append(i)
				j = n // i
				if j != i:
					ans.append(j)
			i += 1
		ans.sort()
		c = 0
		ans = ans[::-1]
		for i in ans:
			if i <= k:
				print(n // i)
				c = 1
				break
		if c == 0:
			print(n)
T = 1
T = int(input())
for _ in range(1, T + 1):
	print('Case #', _, file=sys.stderr)
	solve()


def factors(n):
	z = int(n ** 0.5) + 1
	l = []
	for i in range(1, z):
		if n % i == 0:
			l.append(i)
			k = n // i
			if k != i:
				l.append(k)
	l.sort()
	return l

def bsearch(l, k):
	lo = 0
	hi = len(l) - 1
	while lo <= hi:
		mid = lo + (hi - lo) // 2
		if l[mid] == k:
			return k
		elif l[mid] < k:
			lo = mid + 1
		else:
			hi = mid - 1
	return l[hi]
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = factors(n)
	print(n // bsearch(l, k))


t = int(input())
c = [0] * t
for i in range(t):
	(a, b) = map(int, input().split())
	k = [a, b]
	c[i] = k
from functools import reduce

def print_factors(n):
	return reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))
for i in range(t):
	p = print_factors(c[i][0])
	p.sort(reverse=True)
	for j in range(len(p)):
		s = 0
		if p[j] <= c[i][1]:
			s = p[j]
			break
	print(int(c[i][0] / s))


import math

def fact(n):
	temp = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				temp.append(i)
			else:
				temp.append(i)
				temp.append(n // i)
		i += 1
	return temp
test = int(input())
for i in range(test):
	(n, k) = [int(x) for x in input().split(' ')]
	div = fact(n)
	ans = []
	l = len(div)
	for j in range(l):
		if div[j] <= k:
			ans.append(n // div[j])
	print(min(ans))


from math import sqrt
for t in range(int(input())):
	(n, k) = list(map(int, input().split()))
	found = False
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0 and k >= n // i:
			print(i)
			found = True
			break
	if not found:
		for i in range(int(sqrt(n)), 0, -1):
			if n % i == 0 and k >= i:
				print(n // i)
				found = True
				break
	if not found:
		print(n)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	q = n ** 0.5 + 2
	q = min(int(q), k)
	re = 10000000000
	for i in range(1, q + 1):
		if n > i and n % i == 0:
			re = min(re, n // i)
			if n // i <= k:
				re = min(re, i)
	if re == 10000000000:
		re = k
	if n == 1:
		re = 1
	print(re)


for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	if k >= n:
		print(1)
		continue
	j = 1
	a = []
	while j * j < n and j < k:
		j += 1
		if n % j == 0:
			a.append(j)
			a.append(n // j)
	a.sort()
	ans = n
	for i in a:
		if i <= k:
			ans = n // i
	print(ans)


def mind(a, b):
	ans = a
	for i in range(1, min(int(a ** 0.5) + 1, b + 1)):
		if not a % i:
			if a // i > b:
				ans = min(a // i, n)
			else:
				ans = min(i, ans)
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(mind(n, k))


import math

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

def greatdiv(n, k):
	ans = n
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n // i <= k:
				ans = min(i, ans)
			if i <= k:
				ans = min(n // i, ans)
	return ans
T = int(input())
for i in range(T):
	(a, b) = list(map(int, input().split()))
	if a <= b:
		print(1)
	else:
		print(greatdiv(a, b))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		m = n
		for i in range(2, int(math.sqrt(n) + 1)):
			if n % i == 0:
				if m > i and i <= k:
					if n // i <= k:
						m = i
					else:
						m = n // i
		print(m)


import math

def fact(num):
	ans = []
	x = int(math.sqrt(num)) + 1
	for i in range(1, x):
		if num % i == 0:
			t = num // i
			if i == t:
				ans.append(i)
			else:
				ans.append(i)
				ans.append(t)
	return ans
t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	lis = fact(n)
	lis.sort(reverse=True)
	for i in lis:
		if i <= k:
			print(n // i)
			break


def factors(n):
	i = 1
	fctrs = set()
	while i * i <= n:
		if n % i == 0:
			fctrs.add(i)
			if n // i != i:
				fctrs.add(n // i)
		i += 1
	return fctrs
t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	f = factors(n)
	f = sorted(f)
	largest = f[-1]
	for i in range(len(f)):
		if f[i] > k:
			largest = f[i - 1]
			break
	print(n // largest)


t = int(input())
for qwe in range(t):
	(n, k) = map(int, input().split())
	listt = []
	for i in range(int(n ** 0.5) + 2, 0, -1):
		if n % i == 0:
			t1 = i
			t2 = n // i
			if t1 <= k:
				listt.append(n // t1)
			if t2 <= k:
				listt.append(n // t2)
	print(min(listt))


t = int(input())

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return 0
	return 1
while t:
	t -= 1
	(x, k) = map(int, input().split())
	if x <= k:
		print(1)
	elif isprime(x) or k == 1:
		print(x)
	else:
		ans = 100000000000
		for i in range(2, int(x ** 0.5) + 1):
			if x % i == 0 and i <= k:
				ans = min(ans, x // i)
				if x // i <= k:
					ans = min(ans, i)
		ans = min(ans, x)
		print(ans)


import sys
import math
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	(n, k) = [int(c) for c in input().split()]
	n2 = int(n ** 0.5)
	ans = n
	for i in range(1, min(n2, k) + 1):
		if n % i == 0:
			ans = min(ans, n // i, n if n // i > k else i)
	print(ans)


import math

def getDivisors(n):
	list = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			list.append(i)
			if n / i != i:
				list.append(n // i)
	list.sort(reverse=True)
	return list
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if k >= n:
		print(1)
	else:
		for c in getDivisors(n):
			if c <= k:
				print(n // c)
				break


def prime(n, k):
	l = []
	h = int(n ** (1 / 2)) + 1
	for i in range(h, 1, -1):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	if len(l) == 0:
		return -1
	return l
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		k1 = prime(n, k)
		if k1 == -1:
			print(n)
		else:
			k1 = sorted(k1, reverse=True)
			flag = 0
			for j in k1:
				if j <= k:
					flag = 1
					break
			if flag == 0:
				print(n)
			else:
				print(n // j)


import math

def printDivisors(n):
	i = 1
	d = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				d.append(i)
			else:
				d.append(i)
				d.append(n // i)
		i = i + 1
	d.sort()
	return d
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		div = printDivisors(n)
		x = len(div)
		for i in range(x - 1, -1, -1):
			if div[i] <= k:
				print(n // div[i])
				break


import math
t = int(input())
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	lim = int(math.sqrt(n))
	ans = -1
	for div in range(lim, 0, -1):
		if n % div == 0:
			if div <= k:
				ans = max(ans, div)
			if n / div <= k:
				ans = max(ans, n / div)
	print(int(n / ans))


t = int(input())
while t != 0:
	t -= 1
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		p = int(n ** 0.5)
		ans = 1000000000000000001
		for i in range(1, p + 1):
			if n % i == 0:
				if n // i <= k:
					ans = min(ans, i)
				if i <= k:
					ans = min(ans, n // i)
		print(ans)


import math

def printDivisors(n):
	al = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				al.append(i)
			else:
				al.append(i)
				al.append(n // i)
		i = i + 1
	return al

def f(a, b):
	if b == 1:
		return a
	al = printDivisors(a)
	al.sort()
	tt = al[-1]
	for i in range(len(al)):
		if al[i] > b:
			tt = al[i - 1]
			break
	return int(a / tt)
for tc in range(int(input())):
	ll = list(map(int, input().split()))
	print(f(ll[0], ll[1]))


import math
import bisect

def isprime(n, k):
	l = [1]
	for i in range(math.ceil(math.sqrt(n)), 0, -1):
		if n % i == 0:
			l.extend([i, n // i])
	return list(set(l))

def main():
	for _ in range(int(input())):
		(n, k) = list(map(int, input().split()))
		if n <= k:
			print(1)
		else:
			x = isprime(n, k)
			x.sort()
			y = bisect.bisect_left(x, k)
			if k == x[y]:
				print(n // x[y])
			else:
				print(n // x[y - 1])
main()


import math
t = int(input())
for f in range(t):
	inp = input().split()
	n = int(inp[0])
	k = int(inp[1])
	ans = 0
	for i in range(1, int(math.floor(math.sqrt(n))) + 1):
		if n % i == 0 and i <= k:
			ans = max(ans, i)
		if n % i == 0 and n / i <= k:
			ans = max(ans, n / i)
	print(int(n / ans))


from math import sqrt

def main():
	for P in range(int(input())):
		wyn = 0
		(jaka, doIlu) = list(map(int, input().split()))
		czy_break = False
		if jaka <= doIlu:
			print(1)
			continue
		for i in range(1, int(sqrt(jaka) + 1)):
			if jaka % i == 0:
				if jaka // i <= doIlu:
					print(i)
					czy_break = True
					break
				elif i <= doIlu:
					wyn = i
		if not czy_break:
			print(jaka // wyn)
main()


import math as m

def cp(n):
	z = n
	w = [z]
	for i in range(2, int(m.sqrt(z)) + 1):
		if i <= b:
			if n % i == 0:
				if n // i <= b:
					z = i
					break
				else:
					w.append(n // i)
	return min(z, min(w))
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b == 1:
		print(a)
	elif b >= a:
		print(1)
	else:
		q = cp(a)
		print(q)


t = int(input())
for x in range(t):
	(n, k) = map(int, input().split())
	if k >= n or n == 1:
		print(1)
	else:
		i = 1
		div = 1
		while i * i <= n:
			if n % i == 0:
				if i <= k:
					div = max(div, i)
				if n // i <= k:
					div = max(div, n // i)
			i += 1
		print(n // div)


from __future__ import division, print_function
mod = int(1000000000.0 + 7)
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

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

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(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
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f[-1]
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def nextPerfectSquare(N):
	nextN = math.floor(math.sqrt(N)) + 1
	return nextN * nextN

def main():
	for _ in range(inin()):
		(n, k) = map(int, input().split())
		arr = []
		temp = n
		if n <= k:
			print(1)
		else:
			for i in range(2, math.ceil(math.sqrt(n)) + 1):
				if n % i == 0:
					arr.append(n // i)
			for i in range(0, len(arr)):
				if arr[i] <= k:
					temp = min(temp, n // arr[i])
				if n // arr[i] <= k:
					temp = min(temp, arr[i])
			print(temp)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
main()


t = int(input())
for i in range(t):
	(n1, k1) = input().split(' ')
	n = int(n1)
	k = int(k1)
	a = b = t = 0
	arr = []
	if k >= n:
		print(1)
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				arr = arr + [i]
				if n // i <= k:
					a = 1
					print(i)
					break
		if a == 0:
			t = len(arr) - 1
			while t >= 0:
				if arr[t] <= k:
					b = 1
					print(n // arr[t])
					break
				t = t - 1
			if b == 0:
				print(n)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	lis = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			lis.append(i)
			lis.append(n // i)
	lis.sort(reverse=True)
	for num in lis:
		if num <= k:
			print(n // num)
			break


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 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 print_list(l):
	print(' '.join(map(str, l)))
from math import ceil, floor, sqrt
for _ in range(N()):
	(n, k) = RL()
	if k >= n:
		print(1)
	else:
		tmp = floor(n ** 0.5)
		res = n
		for i in range(1, tmp + 1):
			if n % i == 0:
				(a, b) = (i, n // i)
				if b <= k:
					res = i
					break
				elif a <= k:
					res = min(res, b)
				else:
					break
		print(res)


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	x = min(k, int(math.sqrt(n)))
	t = 0
	for j in range(2, x + 1):
		if n % j == 0:
			t = 1
			temp = n // j
			if temp <= k:
				temp = j
				break
	if t == 1:
		print(temp)
	else:
		print(n)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		temp = min(k + 1, int(n ** 0.5) + 1)
		ans = -1
		for i in range(1, temp):
			if n % i == 0:
				if i <= k and i > ans:
					ans = i
				if n // i <= k and n // i > ans:
					ans = n // i
		print(n // ans)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = set()
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			s.add(i)
			s.add(n / i)
	ma = -1
	for i in s:
		if i <= k:
			ma = max(ma, i)
	print(int(n / ma))


import sys
from collections import defaultdict as dd
from queue import Queue
import math
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass

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 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 i in range(int(input())):
	(n, k) = map(int, input().split())
	r = sorted(printDivisors(n))[::-1]
	l = 1
	for i in r:
		if i <= k:
			l = i
			break
	print(n // l)


import math
for _ in range(int(input())):
	mx = -1
	(n, k) = map(int, input().split())
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i <= k:
				mx = max(i, mx)
				if n // i <= k:
					mx = max(n // i, mx)
	print(n // mx)


from math import sqrt
t = int(input())
for T in range(t):
	(n, k) = map(int, input().split())
	i = 1
	s = set()
	while i <= sqrt(n) and i <= k:
		if n % i == 0:
			s.add(i)
			if n / i <= k:
				s.add(n / i)
		i += 1
	x = max(s)
	print
	ans = int(n / x)
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	ans = 1000000000
	if n == k:
		print(1)
		continue
	if k == 1:
		print(n)
		continue
	sq = int(n ** 0.5 + 1)
	for i in range(1, min(k, sq) + 1):
		if n % i == 0:
			if i <= k:
				ans = min(ans, n / i)
			if n / i <= k:
				ans = min(ans, i)
	print(int(ans))


for t in range(int(input())):
	(n, k) = map(int, input().split())
	mx = n
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i <= k:
				mx = min(mx, n // i)
			if n // i <= k:
				mx = min(mx, i)
	print(mx)


t = int(input())
import math
for i in range(t):
	(n, k) = map(int, input().strip().split())
	if n >= k:
		q = []
		for i in range(1, int(math.sqrt(n) + 1)):
			if n % i == 0:
				q.append(i)
				q.append(n // i)
		f = []
		for i in range(len(q)):
			if q[i] <= k:
				f.append(q[i])
		print(n // max(f))
	if n < k:
		print(1)


class Solution:

	def __init__(self):
		self.t = int(input())
		self.n = int
		self.k = int

	def read(self):
		(self.n, self.k) = [int(x) for x in input().split()]

	def solve(self):
		sol = 1
		for i in range(1, int(self.n ** 0.5) + 1):
			if self.n % i == 0 and self.n // i <= self.k:
				print(i)
				return
			if self.n % i == 0 and i <= self.k:
				sol = self.n // i
		print(sol)
sol = Solution()
while sol.t:
	sol.t -= 1
	sol.read()
	sol.solve()


t = int(input())
import math
for _ in range(t):
	x = 1
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	elif k == 1:
		print(n // x)
	else:
		v = int(math.sqrt(n)) + 1
		for i in range(2, v):
			if n % i == 0 and i <= k:
				if int(n / i) <= k:
					x = int(n / i)
					break
				else:
					x = i
		print(n // x)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		j = 1
		ans = n
		while j * j <= n:
			if n % j == 0:
				if j <= k:
					ans = min(ans, n // j)
				if n // j <= k:
					ans = min(ans, j)
			j += 1
		print(ans)


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
	l1 = []
	for i in range(2, n + 1):
		if prime[i] == -1:
			l1.append(i)
	return l1

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(ll, l, r, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		if ll[mid] <= val:
			ans = mid
			return bin(ll, mid + 1, r, val, ans)
		else:
			return bin(ll, l, mid - 1, val, ans)

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

def check(n):
	val = 0
	while n != 0:
		if n % 10 > 1:
			val = -1
			break
		n = n // 10
	return val

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
t = int(input())
for i in range(t):
	l = []
	(n, k) = map(int, input().split())
	for j in range(1, int(math.sqrt(n)) + 1):
		if n % j == 0:
			if n // j == j:
				l.append(n // j)
			else:
				l.append(j)
				l.append(n // j)
	l.sort(reverse=True)
	ans = 1
	for j in range(len(l)):
		if n % l[j] == 0 and l[j] <= k:
			ans = n // l[j]
			break
	print(ans)


import math
t = int(input())

def solve(n):
	minm = n
	for i in range(2, min(k + 1, int(math.sqrt(n)) + 1)):
		if n % i == 0:
			if n // i <= k and i <= minm:
				return i
			else:
				minm = n // i
	return minm
for _ in range(t):
	(n, k) = map(int, input().split(' '))
	if n <= k:
		print(1)
	else:
		print(solve(n))


import math
t = int(input(''))
while t > 0:
	(n, k) = map(int, input().split())
	f = []
	flag = 0
	for i in range(1, math.floor(n ** 0.5) + 1, 1):
		if n % i == 0:
			f.append(i)
			if n // i <= k:
				print(i)
				flag = 1
				break
	if flag == 0:
		for h in range(len(f) - 1, -1, -1):
			if f[h] <= k:
				print(n // f[h])
				break
	t -= 1


import queue
import math
t = int(input())
while t:
	line = input().split()
	(n, k) = (int(line[0]), int(line[1]))
	i = 1
	M = 0
	while i * i <= n:
		if n % i == 0:
			if i <= k:
				M = max(M, i)
			if n // i <= k:
				M = max(M, n // i)
		i += 1
	print(n // M)
	t -= 1


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
import sys
input = sys.stdin.readline
(t,) = map(int, input().split())
for _ in range(t):
	(a, b) = map(int, input().split())
	rs = make_divisors(a)
	for r in rs[::-1]:
		if r <= b:
			print(a // r)
			break


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(' ')))
	if k >= n:
		print(1)
	else:
		minimo = n + 1
		lista = list(divisores(n))
		for i in range(len(lista)):
			d = n // lista[i]
			if d < minimo and lista[i] <= k:
				minimo = d
		print(minimo)


def factors(n):
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			yield i
			yield (n // i)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	mini = n
	for i in factors(n):
		if i <= k and n // i < mini:
			mini = n // i
	print(mini)


import math

def main():
	t = int(input())
	for i in range(0, t):
		d = list(map(int, input().split()))
		n = d[0]
		k = d[1]
		m = max(list(filter(lambda x: x <= k, divs(n))))
		print(n // m)

def divs(n):
	divs1 = list(filter(lambda x: n % x == 0, range(1, int(math.sqrt(n)) + 1)))
	divs2 = list(map(lambda x: n // x, divs1))
	divs1.extend(divs2)
	divs = list(set(divs1))
	divs.sort()
	return divs
main()


import math

def solve():
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
		return
	else:
		i = 2
		min1 = pow(10, 10)
		while i <= math.sqrt(n):
			if n % i == 0:
				v = n // i
				if k >= v:
					min1 = min(min1, i)
				if k >= i:
					min1 = min(min1, v)
			i = i + 1
		if min1 == pow(10, 10):
			print(n)
		else:
			print(min1)
for _ in range(int(input())):
	solve()


def find_divisors(x):
	s = []
	for i in range(1, int(pow(x, 0.5)) + 1):
		if x % i == 0:
			s.append(i)
			if i != x / i:
				s.append(int(x / i))
	return sorted(s)
N = int(input())
answers = []
for i in range(N):
	(n, k) = map(int, input().split())
	arr = sorted(find_divisors(n))
	t = len(arr) - 1
	flag = False
	while t >= 0:
		if arr[t] <= k:
			flag = True
			answers.append(n // arr[t])
			break
		else:
			t -= 1
	if not flag:
		answers.append(n)
for i in answers:
	print(i)


from math import sqrt
q = int(input())
for w in range(q):
	(n, k) = map(int, input().split())
	s = int(sqrt(n))
	m = n
	for i in range(1, s + 1):
		if n % i == 0:
			if i <= k:
				m = min(m, n // i)
			if n // i <= k:
				m = min(m, i)
	print(m)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif n % k == 0:
		print(n // k)
	else:
		ans = float('inf')
		for i in range(1, int(math.sqrt(n)) + 1):
			if n % i == 0:
				if n // i <= k:
					ans = i
					break
				elif i <= k:
					ans = n // i
		print(ans)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b >= a:
		print(1)
	else:
		ans = a
		for i in range(2, int(math.sqrt(a)) + 1):
			if a % i == 0:
				if a // i <= b:
					print(i)
					break
				if i <= b:
					ans = a // i
		else:
			print(ans)


from math import sqrt
for t in range(int(input())):
	(i_lopat, k) = map(int, input().split())
	wynik = 0
	if i_lopat <= k:
		print(1)
	elif k == 1:
		print(i_lopat)
	elif i_lopat % k == 0:
		print(i_lopat // k)
	else:
		for x in range(2, int(sqrt(i_lopat)) + 2):
			if i_lopat % x == 0:
				if i_lopat // x <= k:
					print(x)
					break
				if x <= k:
					wynik = i_lopat // x
		else:
			if wynik:
				print(wynik)
			else:
				print(i_lopat)


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, input().split()))

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

def I():
	return int(input())
P = 1000000007

def factors(x):
	result = []
	i = 1
	while i * i <= x:
		if x % i == 0:
			result.append(i)
			if x // i != i:
				result.append(x // i)
		i += 1
	return result

def main():
	for t in range(I()):
		(n, k) = In()
		if k // n >= 1:
			print(1)
		else:
			res = sorted(factors(n), reverse=True)
			for i in range(len(res)):
				if res[i] <= k:
					print(n // res[i])
					break
main()


import math

def get_divisors(n):
	i = 2
	ans1 = []
	ans2 = []
	while i <= math.sqrt(n):
		if n % i == 0:
			ans1.append(i)
			if n // i != i:
				ans2.append(n // i)
		i += 1
	return ans1 + list(reversed(ans2))

def solve(n, k):
	if k >= n:
		return 1
	for div in get_divisors(n):
		if n // div <= k:
			return div
	return n
t = int(input())
for i in range(t):
	(n, k) = (int(p) for p in input().split())
	print(solve(n, k))


import io
import os
from collections import Counter, defaultdict, deque
import math

def factors(n):
	fhead = []
	ftail = []
	for x in range(1, int(math.sqrt(n)) + 1):
		if n % x == 0:
			fhead.append(x)
			if x * x != n:
				ftail.append(n // x)
	return fhead + ftail[::-1]

def solve(N, K):
	for factor in reversed(factors(N)):
		if factor <= K:
			return N // factor
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 d(a):
	divs = []
	for i in range(1, int(a ** 0.5) + 1):
		if a % i == 0:
			divs.append(i)
			divs.append(a // i)
	return sorted(divs, reverse=True)
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	l = d(n)
	for i in l:
		if i <= k:
			print(n // i)
			break


import math
I = lambda : list(map(int, input().split()))
t = I()[0]
while t:
	t -= 1
	(n, k) = I()
	a = math.ceil(n / k)
	if n <= k:
		print(a)
	else:
		ans = 1
		i = 1
		while i * i <= n:
			if n % i == 0:
				if i <= k:
					ans = max(ans, i)
				if n // i <= k:
					ans = max(ans, n // i)
			i += 1
		print(n // ans)


from math import sqrt, ceil
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	sol = 0
	if n <= k:
		sol = 1
	else:
		factores = []
		for i in range(1, ceil(sqrt(n)) + 1):
			if n % i == 0:
				factores.append(i)
				factores.append(n // i)
		factores.sort(reverse=True)
		for f in factores:
			if f <= k:
				sol = n // f
				break
	print(sol)


import math
t = int(input())
for _ in range(0, t):
	(n, k) = map(int, input().strip().split(' '))
	maxdiv = 1
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n / i == i:
				if i <= k:
					maxdiv = max(maxdiv, i)
			else:
				if i <= k:
					maxdiv = max(maxdiv, i)
				if n / i <= k:
					maxdiv = max(maxdiv, n // i)
	print(n // maxdiv)


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 < k or n == k:
		print(1)
	elif k == 1:
		print(n)
	else:
		a = factors(n)
		a.append(n)
		a.sort()
		for i in a[::-1]:
			if i <= k:
				print(n // i)
				break


import sys, math, cmath, time
start_time = time.time()
global tt

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()
	q = []
	for i in range(1, math.ceil(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	q.sort()
	q.append(k + 1)
	for i in range(1, len(q)):
		if k < q[i]:
			w = q[i - 1]
			break
	print(n // w)

def main():
	global tt
	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()


from math import sqrt
t = int(input())
for i in range(t):
	x = input()
	s = x.split()
	n = int(s[0])
	k = int(s[1])
	if k >= n:
		print(1)
	else:
		t = 0
		j = 2
		div = []
		while j <= sqrt(n):
			if n % j == 0:
				t = t + 1
				if n / j <= k:
					div.append(j)
				elif j <= k:
					div.append(n / j)
			j = j + 1
		if t == 0:
			print(n)
		elif len(div) > 0:
			print(int(min(div)))
		else:
			print(n)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	i = 1
	ans = n
	while i <= k and i * i <= n:
		if n % i == 0:
			rem = int(n / i)
			if rem <= k and i < ans:
				ans = min(ans, i)
			else:
				ans = min(rem, ans)
		i += 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	i = 1
	s = []
	while i * i <= n:
		if n % i == 0:
			s.append(i)
			s.append(n // i)
		i += 1
	s = sorted(s)[::-1]
	for x in s:
		if x <= k:
			print(n // x)
			break


def main():
	import sys
	sys.setrecursionlimit(10 ** 6)
	input = sys.stdin.readline
	T = int(input())
	for t in range(T):
		(n, k) = [int(x) for x in input().strip().split()]
		ans = n
		for i in range(1, min(k, int(n ** 0.5)) + 1):
			if n % i == 0:
				m = n // i
				ans = min(ans, n // i)
				if m <= k:
					ans = min(ans, n // m)
		print(ans)
main()


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
		continue
	i = 1
	total = float('inf')
	ans = 0
	while i * i <= n:
		if n % i == 0:
			quot = n // i
			if quot <= k:
				if quot < total:
					total = i
					ans = i
			if i <= k:
				if i < total:
					total = quot
					ans = quot
		i += 1
	print(ans)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	mini = n
	for i in range(1, min(k, math.floor(n ** 0.5)) + 1):
		if n % i == 0 and int(n / i) <= k:
			mini = i
			break
		if n % i == 0:
			mini = int(n / i)
	print(mini)


from sys import stdin, stdout
import math
from collections import Counter, deque
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
IN = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()
mod = 1000000007

def s(a):
	print(' '.join(list(map(str, a))))
for i in range(I()):
	(n, k) = M()
	m = 1
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n / i != i:
				if k >= n / i:
					m = max(n / i, m)
			if k >= i:
				m = max(i, m)
	print(int(n // m))


import math

def find_div(x):
	div = []
	for i in range(1, int(math.sqrt(x) + 1)):
		if x % i == 0:
			div.append(i)
			if i * i != x:
				div.append(x // i)
	return div
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		div = find_div(n)
		ans = 1
		for x in div:
			if x <= k:
				ans = max(x, ans)
		print(n // ans)


import math
T = int(input())
for t in range(T):
	(n, k) = [int(i) for i in input().split()]
	if n == 1:
		print(1)
	else:
		d = 1
		for i in range(1, min(int(math.sqrt(n)), k) + 1):
			if n % i == 0:
				if n // i <= k:
					d = max([d, i, n // i])
				else:
					d = max(d, i)
		print(n // d)


def solve(n, k):
	i = 1
	ans = 0
	while i * i <= n:
		if n % i == 0:
			d = n // i
			ans1 = 0
			if d <= k:
				ans1 = d
			elif i <= k:
				ans1 = i
			if ans1 > ans:
				ans = ans1
		i += 1
	print(n // ans)

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


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		j = 1
		ans = 0
		while j <= math.sqrt(n):
			if n % j == 0:
				if n / j <= k:
					ans = max(ans, n / j)
				elif j <= k:
					ans = max(ans, j)
			j += 1
		print(int(n / ans))


def divisor(n):
	fac = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			fac.append(i)
			if i * i != n:
				fac.append(n // i)
	return sorted(fac, reverse=True)
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	for x in divisor(n):
		if x <= k:
			print(n // x)
			break


T = int(input())

def getMinDiv(n, k):
	r = int(pow(n, 0.5))
	d = 1
	if k <= r:
		for i in range(1, k + 1):
			if n % i == 0:
				d = int(n / i)
	else:
		for i in range(1, r + 1):
			if n % i == 0 and n / i <= k:
				d = int(i)
				return d
			if n % i == 0:
				d = int(n / i)
	return d
while T > 0:
	(n, k) = [int(el) for el in input().split(' ')]
	if n <= k:
		print(1)
	else:
		d = getMinDiv(n, k)
		if d == 0:
			print(n)
		else:
			print(d)
	T -= 1


def buyingShovels(n, k):
	ans = float('inf')
	if k >= n:
		return 1
	for x in range(min(int(n ** 0.5), k), 0, -1):
		if n % x == 0:
			if n / x <= k:
				a = min(x, int(n / x))
			else:
				a = int(n / x)
			ans = min(a, ans)
	return ans
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(buyingShovels(n, k))


import sys
input = sys.stdin.buffer.readline

def print(val):
	sys.stdout.write(str(val) + '\n')

def prog():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		divisors = []
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				if i <= k:
					divisors.append(i)
				new = n // i
				if new <= k:
					divisors.append(new)
		print(n // max(divisors))
prog()


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	x = input().split()
	x = [int(a) for a in x]
	(n, k) = (x[0], x[1])
	divs = []
	for j in range(1, int(n ** 0.5 + 2)):
		if n % j == 0:
			divs.append(j)
			divs.append(n // j)
	divs.sort()
	best = 0
	for d in divs:
		if d < k + 1:
			best = n // d
	print(best)


from math import sqrt

def get_divisors(n):
	m = int(sqrt(n))
	s = set()
	for d in range(1, m + 1):
		if n % d == 0:
			s.add(d)
			s.add(n // d)
	return list(s)
for _ in [0] * int(input()):
	(n, k) = map(int, input().split())
	divisors = get_divisors(n)
	divisors.sort()
	m = 1
	for d in divisors:
		if d > k:
			break
		m = max(d, m)
	print(n // m)


from math import sqrt
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	ans = n + 2
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			(c1, c2) = (i, n // i)
			if c1 <= k and n // c1 < ans:
				ans = n // c1
			if c2 <= k and n // c2 < ans:
				ans = n // c2
	print(ans)


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	res = 0
	for j in range(min(int(math.sqrt(n)) + 1, k), 0, -1):
		if n % j == 0:
			comp = n // j
			if comp <= k:
				res = max(comp, j)
			res = max(res, j)
	print(n // res)


def count_dividers(x):
	ans = set()
	for i in range(1, int(x ** 0.5) + 1):
		if x % i == 0:
			ans.add(i)
			ans.add(n // i)
	return sorted(list(ans))
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(n // list(filter(lambda x: x <= k, count_dividers(n)))[-1])


import math
for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = []
	if k >= n:
		s = 1
	else:
		r = int(math.sqrt(n)) + 1
		q = 0
		for i in range(2, r):
			if n % i == 0:
				if n // i <= k:
					a.append(i)
					q = 1
				if i <= k:
					a.append(n // i)
					q = 1
		if q == 1:
			s = min(a)
		else:
			s = n
	print(s)


import math

def main():
	tc = int(input())
	while tc != 0:
		tc -= 1
		(n, k) = map(int, input().split(' '))
		if n <= k:
			print('1')
		else:
			prime = 1
			mn = n
			for i in range(2, math.ceil(math.sqrt(n)) + 1):
				if n % i == 0:
					prime = 0
				if prime == 0 and n % i == 0:
					x = n // i
					if i <= k:
						mn = min(mn, x)
					if x <= k:
						mn = min(mn, i)
			if prime == 1:
				print(n)
			else:
				print(mn)
main()


tests = int(input())
for i in range(tests):
	(n, k) = map(int, input().split())
	sol = 1
	i = 1
	arr = []
	while i * i <= n and i <= k:
		if n % i == 0:
			if n / i <= k:
				arr.append(int(i))
			else:
				arr.append(int(n / i))
		i += 1
	print(min(arr))


import math

def check(k, n):
	arr1 = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				arr1.append(i)
			else:
				arr1.append(i)
				arr1.append(n // i)
		i += 1
	arr1.sort()
	ans = 1
	for i in arr1:
		if i <= k:
			ans = i
	return n // ans
t = int(input())
while t:
	arr = list(map(int, input().strip().split()))[:2]
	(n, k) = (arr[0], arr[1])
	if k >= n:
		print(1)
	else:
		print(check(k, n))
	t -= 1


def factorization(n):
	D = {}
	a = n
	p = 2
	while a != 1:
		cnt = 0
		while a % p == 0:
			cnt += 1
			a //= p
		if cnt != 0:
			D[p] = cnt
		p += 1
		if p * p > n and a != 1:
			D[a] = 1
			break
	return D

def Vanilla(D):
	F = [1]
	for i in D:
		mL = F[:]
		dp = i
		for j in range(D[i]):
			for k in mL:
				F.append(dp * k)
			dp *= i
	F.sort()
	return F
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	S = factorization(n)
	V = Vanilla(S)
	M = n
	for i in V:
		if i <= k:
			M = min(M, n // i)
	print(M)


import sys

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

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

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

def div(n):
	i = 1
	c = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				c.append(i)
			else:
				c.append(i)
				c.append(n // i)
		i = i + 1
	return list(set(c))
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	li = div(n)
	li.sort()
	d = []
	for i in range(len(li)):
		if li[i] > k:
			break
		d.append(n // li[i])
	print(min(d))


import sys

def solve(n, k):
	if k >= n:
		return 1
	else:
		v = 2
		best = n
		while v * v <= n:
			if v > k:
				return best
			elif n % v == 0:
				if n / v <= k:
					return v
				else:
					best = min(best, n // v)
			v += 1
		return best
IN = [x.strip() for x in sys.stdin.readlines()]
T = int(IN[0])
for i in range(T):
	(n, k) = [int(x) for x in IN[1 + i].split(' ')]
	result = solve(n, k)
	print(result)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	var = math.sqrt(n)
	var = int(var)
	l = []
	if k == 1:
		print(n)
	elif n <= k:
		print(1)
	else:
		for i in range(1, var + 1):
			if i <= k:
				if n % i == 0:
					if i <= k:
						l.append(n // i)
					if n // i <= k:
						l.append(i)
		print(min(l))


def check(n, k):
	l = [1]
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			l.append(i)
			l.append(n // i)
	l.sort()
	we = len(l)
	for i in range(we - 1, -1, -1):
		if k >= l[i]:
			return n // l[i]
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		ans = check(n, k)
		print(ans)


import sys
import math
input = sys.stdin.readline
t = int(input())
for test in range(t):
	(n, k) = list(map(int, input().split()))
	flag = 0
	for i in range(1, math.floor(math.sqrt(n)) + 1):
		if n % i == 0:
			if n / i <= k:
				ans = i
				print(int(ans))
				flag = 1
				break
			elif i <= k:
				ans = n / i
	if flag == 0:
		print(int(ans))


def prog():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		divisors = []
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				if i <= k:
					divisors.append(i)
				if n / i <= k:
					divisors.append(n // i)
		print(n // max(divisors))
prog()


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.extend([i, n // i])
		i = i + 1
	return arr
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	factors = sorted(printDivisors(n))
	j = len(factors) - 1
	while j >= 0:
		if factors[j] <= k:
			print(n // factors[j])
			break
		j -= 1


T = int(input())

def make_sosuu(n):
	sosuu = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			sosuu.append(i)
			if i != n // i:
				sosuu.append(n // i)
	sosuu.sort()
	return sosuu
for i in range(T):
	(A, B) = list(map(int, input().split()))
	if A <= B:
		print(1)
	else:
		P = make_sosuu(A)
		P = [i for i in P if i <= B]
		print(A // max(P))


z = lambda : int(input())
z1 = lambda : input()
z2 = lambda : map(int, input().split())
import math

def prime(a):
	if a % 2 == 0:
		return False
	i = 3
	z = pow(a, 0.5)
	while i < z:
		if a % i == 0:
			return False
		i += 2
	return True
for _ in ' ' * z():
	(a, b) = z2()
	if a <= b:
		print(1)
	else:
		t = 0
		for i in range(min(int(math.sqrt(a)), b), 0, -1):
			if a % i == 0:
				if i > t:
					t = i
				if a // i > t and a // i <= b:
					t = a // i
		print(a // t)


from math import *
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print('1')
	else:
		a = sqrt(n)
		a = floor(a)
		a = a + 1
		l = []
		b = 1
		for i in range(2, a + 1):
			if n % i == 0:
				l.append(i)
				b = i
		if b == 1:
			print(n)
		else:
			x = len(l)
			m = l[x - 1]
			if n // m > k:
				if k < l[0]:
					print(n)
				else:
					for i in range(x):
						if k >= l[i]:
							ans = n // l[i]
						else:
							break
					print(ans)
			else:
				for i in range(x):
					d = n // l[i]
					if k >= d:
						c = l[i]
						f = 1
						break
				print(c)


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
import string

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):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

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 flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

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

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

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

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

def prr(a, sep=' ', end='\n'):
	print(sep.join(map(str, a)), end=end)

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

def ddl():
	return collections.defaultdict(list)
for _ in range(ii()):
	(n, k) = mi()
	res = n
	for i in divs(n):
		if i <= k:
			res = min(res, n // i)
	print(res)


t = int(input())
for i in range(0, t):
	(n, k) = map(int, input().split())
	j = 1
	m = n
	while j <= n ** 0.5:
		if n % j == 0 and n <= j * k:
			m = min(m, j)
			break
		if n % j == 0 and j <= k:
			m = min(m, int(n / j))
		j += 1
	print(m)


import math
d = []

def printDivisors(n):
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				d.append(i)
			else:
				d.extend([i, n // i])
		i = i + 1
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	printDivisors(n)
	d.sort()
	for i in d[::-1]:
		if i <= k:
			print(n // i)
			d = []
			break


for i in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		count = 0
		l1 = []
		for j in range(2, int(pow(n, 0.5)) + 1):
			if n % j == 0:
				count = 1
				if j <= k:
					l1.append(j)
				if int(n / j) <= k:
					l1.append(int(n / j))
		if count == 0:
			print(n)
			continue
		elif len(l1) == 0:
			print(n)
		else:
			print(int(n / max(l1)))


from math import *
t = int(input())
while t > 0:
	a = list(map(int, input().split()))
	(n, k) = (a[0], a[1])
	b = []
	for i in range(1, floor(sqrt(n)) + 1):
		if n % i == 0:
			b.append(int(i))
			b.append(int(n / i))
	b = sorted(b)
	for j in b:
		if n / j <= k:
			print(j)
			break
	t -= 1


import math

def divisors(n):
	l = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	return l
import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = int(stdin.readline())
for _ in range(t):
	(n, k) = list(map(int, stdin.readline().rstrip().split()))
	if n <= k:
		print(1)
	else:
		l = divisors(n)
		ans = n
		for i in l:
			if i <= k:
				ans = min(ans, n // i)
		print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 1
	f = []
	if k < n:
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0 and i <= k:
				f.append(i)
				if n // i <= k:
					f.append(n // i)
		m = max(f)
		ans = n // m
	print(ans)


from sys import stdin, setrecursionlimit as srl
from threading import stack_size, Thread
srl(int(1000000000.0) + 7)
stack_size(int(100000000.0))

def solve():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		j = int(n ** 0.5) + 1
		end = 0
		for i in range(1, j):
			if n % i == 0 and n // i <= k:
				print(i)
				end = 1
				break
			if n % i == 0 and i <= k:
				ans = n // i
		if end == 0:
			print(ans)
Thread(target=solve).start()


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if n <= k:
		print(1)
		continue
	p = []
	ans = float('inf')
	c = 1
	while c * c <= n:
		if n % c == 0 and c <= k:
			ans = min(ans, n // c)
			rem = n // c
			if rem <= k:
				ans = min(ans, n // rem)
		c += 1
	print(ans)


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 <= k:
		print(1)
	else:
		d = sorted(divs(n))
		m = 1
		for item in d:
			if item <= k:
				m = item
		print(n // m)


import collections, heapq, itertools, math, functools
groupby = itertools.groupby
rs = lambda : input()
ri = lambda : int(input())
rm = lambda : map(int, input().split())
rai = lambda : [int(x) for x in input().split()]
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)))

def solve():
	if k >= n:
		return 1
	l = sorted(list(factors(n)), reverse=True)
	for factor in l:
		if factor <= k:
			return n // factor
for t in range(ri()):
	(n, k) = rm()
	print(solve())


def factors(n, k):
	l = [1]
	lx = [n]
	c = True
	for i in range(1, int(n ** 0.5) + 1):
		if i <= k:
			if n % i == 0:
				l.append(i)
				lx.append(n // i)
		else:
			c = False
			break
	if c == False:
		print(lx[-1])
	elif lx[-1] > k:
		print(lx[-1])
	else:
		y = True
		for i in lx[::-1]:
			if i > k:
				print(l[lx.index(x)])
				y = False
				break
			x = i
		if y == True:
			print(l[lx.index(x)])
for _ in range(int(input())):
	[n, k] = list(map(int, input().split()))
	factors(n, k)


import math

def FindFactors(x):
	num_set = set()
	add_list = []
	for i in range(1, math.ceil(math.sqrt(x)) + 1):
		if x % i == 0:
			num_set.add(i)
	for element in num_set:
		add_list.append(int(x / element))
	for element in add_list:
		num_set.add(element)
	return num_set
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	factors_list = list(FindFactors(n))
	factors_list.sort(reverse=True)
	x = 0
	for element in factors_list:
		if element <= k:
			x = element
			break
	print(int(n / x))


from collections import Counter as C, defaultdict as D, deque as Q
from operator import itemgetter as I
from itertools import product as P
from bisect import bisect_left as BL, bisect_right as BR
from heapq import heappush as HPUSH, heappop as HPOP
from math import floor as MF, ceil as MC, gcd as MG, factorial as F, sqrt as SQRT, inf as INFINITY, log as LOG

def player1():
	print('')

def player2():
	print('')

def isPrime(n):
	for i in range(2, MC(SQRT(n)) + 1):
		if n % i == 0:
			return False
	return True

def factors(x, k):
	ans = []
	for i in range(1, MC(SQRT(x)) + 1):
		if x % i == 0:
			ans.append(i)
			if x % (x // i) == 0:
				ans.append(x // i)
	return ans

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		if k == 1:
			print(n)
			continue
		if k >= n:
			print(1)
			continue
		f = factors(n, k)
		f.sort()
		index = BL(f, k)
		if f[index] > k:
			index -= 1
		print(n // f[index])
main()


from math import *
n = int(input())
for j in range(n):
	ab = input().split()
	a = int(ab[0])
	b = int(ab[1])
	y = int(sqrt(a))
	u = min(y, b)
	q = []
	w = []
	for i in range(1, u + 1):
		if a % i == 0:
			x = i
			q.append(x)
			m = a // i
			if m <= b:
				w.append(m)
	if len(w) > 0:
		ans = max(max(q), max(w))
	else:
		ans = max(q)
	print(a // ans)


from math import *
import math

def r1(t):
	return t(input())

def r2(t):
	return [t(i) for i in input().split()]
for zzz in range(r1(int)):
	(n, k) = r2(int)
	i = 2
	ans = n
	while i * i <= n and i <= k:
		if n % i == 0:
			ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
		i += 1
	if n <= k:
		ans = 1
	print(ans)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		print(n)
	elif n <= k:
		print(1)
	else:
		x = n
		for i in range(1, min(int(math.sqrt(n) + 1), k + 1)):
			if n % i == 0:
				x = min(x, n // i)
				if i != n // i and n // i <= k:
					x = min(x, n // (n // i))
		print(x)


import math

def printDivisors(n):
	i = 1
	Ans = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				Ans.append(i)
			else:
				Ans.append(i)
				Ans.append(n // i)
		i = i + 1
	return Ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	factor = printDivisors(n)
	factor.sort(reverse=True)
	for i in factor:
		if i <= k:
			print(n // i)
			break


import math

def Divisors(n):
	i = 1
	ans = []
	while i <= math.sqrt(n):
		if n % i == 0:
			ans.append(i)
			if not n // i == i:
				ans.append(n // i)
		i = i + 1
	return ans
n = 1
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	div = Divisors(n)
	ans = 1
	for i in div:
		if i <= k:
			ans = max(ans, i)
	print(n // ans)


import math

def isprime(n):
	i = 2
	while i * i < n:
		if n % i == 0:
			return False
		i += 1
	return True
TT = int(input())
for _ in range(TT):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
		continue
	printed = False
	ans = n
	p = 2
	while p * p <= n and p <= k:
		if n % p == 0:
			how = n // p
			if how <= k:
				print(p)
				printed = True
				break
			else:
				ans = min(how, ans)
		p += 1
	if not printed:
		print(ans)


import math

class Solution:

	def __init__(self):
		test = int(input())
		for i in range(0, test):
			(n, k) = list(map(int, input().split()))
			self.solve(n, k)

	def solve(self, n, k):
		res = n
		i = 1
		while i * i <= n:
			if n % i == 0:
				if i <= k:
					res = min(res, int(n / i))
				if n / i <= k:
					res = min(res, i)
			i += 1
		print(res)
Solution()


from itertools import takewhile
from math import sqrt

def divisors(n):
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			yield i
			yield (n // i)

def buy(n, k):
	if n <= k:
		return 1
	res = list(takewhile(lambda x: x <= k, sorted(divisors(n))))
	return n // res[-1]

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


from math import *
mod = 1000000007

def main():
	(n, k) = [int(x) for x in input().split(' ')]
	ans = 1
	for i in range(1, ceil(sqrt(n)) + 1):
		if n % i == 0:
			if i <= k:
				ans = max(ans, i)
			if n // i <= k:
				ans = max(ans, n // i)
	print(n // ans)
tt = 1
tt = int(input())
for _ in range(tt):
	main()


def gen(ind):
	global res, cur
	dv.append(res)
	if res == n0:
		return
	for i in range(ind, len(cur)):
		if cur[i] < u[i][1]:
			cur[i] += 1
			res *= u[i][0]
			gen(i)
			res //= u[i][0]
			cur[i] -= 1
ans = []
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	n0 = n
	i = 2
	u = []
	while i * i <= n:
		if n % i == 0:
			u.append([i, 0])
		while n % i == 0:
			u[-1][1] += 1
			n //= i
		i += 1
	if n > 1:
		u.append((n, 1))
	dv = []
	cur = [0] * len(u)
	res = 1
	gen(0)
	dv.sort()
	for i in range(len(dv) - 1, -1, -1):
		if dv[i] <= k:
			ans.append(n0 // dv[i])
			break
print('\n'.join(map(str, ans)))


import math
t = int(input())
while t > 0:
	l = [int(x) for x in input().split()]
	(n, k) = (l[0], l[1])
	i = 1
	divs = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				divs.append(i)
			else:
				divs.append(i)
				divs.append(n // i)
		i += 1
	divs.sort(reverse=True)
	for num in divs:
		if num <= k:
			print(n // num)
			break
	t -= 1


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


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a <= b:
		print(1)
		continue
	c = []
	res = 0
	for x in range(1, b + 1):
		if x * x > a:
			break
		if a % x == 0:
			c.append(a // x)
			c.append(a // c[-1])
	for x in c:
		if x <= b and x > res:
			res = x
	print(a // res)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	mn = n
	if n > k:
		for i in range(int(pow(n, 1 / 2)) + 1, 0, -1):
			if n % i == 0:
				a = i
				b = n // i
				if a <= k and b <= k:
					mn = min(mn, a, b)
				elif a > k and b <= k:
					mn = min(mn, a)
				elif b > k and a <= k:
					mn = min(mn, b)
				else:
					continue
		print(mn)
	else:
		print(1)


from math import sqrt, ceil
for I in range(int(input())):
	(n, k) = map(int, input().split())
	res = [n]
	for i in range(1, ceil(sqrt(n) + 1)):
		if n % i == 0:
			if k >= n // i:
				res.append(i)
			temp = n // i
			if k >= n // temp:
				res.append(temp)
	print(min(res))


def solve(n: int, k: int) -> int:
	assert n > k
	p = n
	for i in range(2, min(k + 1, 40000)):
		if i * i > n:
			break
		(q, r) = divmod(n, i)
		if r == 0:
			p = min(q if q > k else i, p)
	return p
tc = int(input())
while tc > 0:
	(n, k) = map(int, input().split())
	print(1 if n <= k else solve(n, k))
	tc -= 1


import math

def printDivisors(n):
	qq = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				qq.append(i)
			else:
				qq.append(i)
				qq.append(int(n / i))
		i = i + 1
	return qq
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		c = printDivisors(n)
		c.sort()
		for i in range(len(c)):
			if c[i] > k:
				break
		z = c[i - 1]
		print(int(n / z))


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	c = 1
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				if i <= k:
					c = max(c, i)
			else:
				if i <= k:
					c = max(c, i)
				if n / i <= k:
					c = max(c, n // i)
		i = i + 1
	print(n // c)


import math

def divisor(n):
	list = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			list.append(i)
			list.append(n // i)
		i = i + 1
	list.sort()
	list.reverse()
	return list
n = int(input())
for _ in range(n):
	(x, y) = map(int, input().split())
	lt = divisor(x)
	for i in range(len(lt)):
		if lt[i] <= y:
			print(x // lt[i])
			break


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		max1 = 1
		for j in range(1, int(n ** 0.5) + 1):
			if n % j == 0:
				if n / j > max1 and n / j <= k:
					max1 = n / j
				if j > max1 and j <= k:
					max1 = j
		print(int(n / max1))


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()
	div = Math.divisor(N)
	div.sort()
	t = div[0]
	for d in div:
		if d <= K:
			t = d
		else:
			break
	print(N // t)

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


from collections import *
from bisect import *
from math import *
from heapq import *
import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	fac = set()
	for i in range(1, int(pow(n, 0.5) + 1)):
		if n % i == 0:
			fac.add(i)
			fac.add(n // i)
	mip = float('inf')
	for i in fac:
		re = n // i
		if re <= k:
			mip = min(mip, i)
	print(mip)


import math
t = int(input())
for hh in range(0, t):
	(n, k) = [int(x) for x in input().split()]
	i = 1
	maxdiv = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				if i <= k:
					maxdiv = max(maxdiv, i)
			else:
				if i <= k:
					maxdiv = max(maxdiv, i)
				if n // i <= k:
					maxdiv = max(maxdiv, n // i)
		i = i + 1
	print(n // maxdiv)


from math import sqrt

def divs(a):
	primes = [i for i in range(1, int(sqrt(a)) + 2) if a % i == 0]
	other = []
	for i in primes[::-1]:
		if a / i not in primes:
			other.append(int(a / i))
	return primes + other
for t in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	d = divs(n)
	s = [i for i in d if i <= k]
	print(n // max(s))


import math

def factors(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
t = int(input())
while t:
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		l = factors(n)
		l.sort()
		for i in range(len(l) - 1, -1, -1):
			if l[i] <= k:
				print(n // l[i])
				break
	t -= 1


nt = int(input())
from math import *
for _ in range(nt):
	(n, k) = list(map(int, input().split()))
	n2 = ceil(sqrt(n))
	m = 0
	for i in range(n2, 0, -1):
		if n % i == 0:
			j = n // i
			if j <= k:
				m = max(m, j)
			if i <= k:
				m = max(m, i)
	print(n // m)


import math
import sys

def solution(n, k):
	if k == 1:
		return n
	if n == k:
		return 1
	if n == 1:
		return 1
	mn = sys.maxsize
	arr = []
	temp = min(int(math.sqrt(n)) + 1, k + 1)
	for i in range(1, temp):
		if n % i == 0:
			arr.append(i)
			if n // i <= k:
				arr.append(n // i)
	for i in arr:
		mn = min(mn, n // i)
	return mn
for i in range(int(input())):
	(n, k) = [int(x) for x in input().split(' ')]
	print(solution(n, k))


from math import sqrt
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	min_req = n
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0 and i <= k:
			min_req = min(min_req, n // i)
			if n // i <= k:
				min_req = min(i, min_req)
	print(min_req)


from collections import defaultdict as dd
import math
import sys
import heapq
input = sys.stdin.readline

def nn():
	return int(input())

def li():
	return list(input())

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

def lm():
	return list(map(int, input().split()))
q = nn()
for _ in range(q):
	(s, p) = mi()
	divs = []
	n = 1
	while n * n <= s:
		if s % n == 0:
			divs.append(n)
			divs.append(s // n)
		n += 1
	divs.sort()
	max_div = 1
	for div in divs:
		if div <= p:
			max_div = div
		else:
			break
	print(s // max_div)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	factors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			factors.append(i)
			factors.append(n // i)
	factors.sort()
	for val in factors:
		if n // val <= k:
			print(val)
			break


import math

def printDivisors(n, l):
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	l.sort(reverse=True)
for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = []
	printDivisors(n, l)
	for i in range(len(l)):
		if l[i] <= k:
			ans = n // l[i]
			print(ans)
			break


import math
t = int(input())
for i in range(t):
	(n, k) = [int(s) for s in input().split()]
	delims = []
	for i in range(1, math.floor(n ** (1 / 2)) + 1):
		if n % i == 0:
			delims.append(i)
			delims.append(n // i)
	size = 1
	for i in range(len(delims)):
		if delims[i] <= k and delims[i] > size:
			size = delims[i]
	print(n // size)


import math
t = int(input())
for ts in range(t):
	(a, b) = [int(i) for i in input().split()]
	if b >= a:
		print(1)
	else:
		li = 0
		f = True
		for i in range(2, math.ceil(a ** 0.5) + 1):
			if a % i == 0:
				if i <= b:
					li = i
				if a / i <= b:
					print(i)
					f = False
					break
		if f:
			if li != 0:
				print(a // li)
			else:
				print(a)


import sys
import bisect
from functools import reduce
input = sys.stdin.readline

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)))
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	a = sorted(list(all_factors(n)))
	i = bisect.bisect_right(a, k)
	print(n // a[i - 1])


import sys
import heapq
import random
import collections
from functools import reduce

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

def solve(n, k):
	lst = all_divisors(n)
	lst = sorted(list(lst))
	for i in lst[::-1]:
		if i <= k:
			return n // i
	return n

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	return
for case_num in range(int(input())):
	(n, k) = list(map(int, input().split()))
	res = solve(n, k)
	print(res)


import math
t = int(input())
for test in range(t):
	(n, k) = [int(x) for x in input().split()]
	limit = int(math.sqrt(n)) + 1
	factors = []
	for i in range(1, limit):
		if n / i == n // i:
			factors.append(i)
			factors.append(n // i)
	factors.sort()
	num = len(factors)
	for i in range(num - 1, -1, -1):
		if factors[i] <= k:
			print(n // factors[i])
			break


import collections
import itertools

def prime_factors(n):
	i = 2
	while i * i <= n:
		if n % i == 0:
			n /= i
			yield i
		else:
			i += 1
	if n > 1:
		yield n

def prod(iterable):
	result = 1
	for i in iterable:
		result *= i
	return result

def get_divisors(n):
	pf = prime_factors(n)
	pf_with_multiplicity = collections.Counter(pf)
	powers = [[factor ** i for i in range(count + 1)] for (factor, count) in pf_with_multiplicity.items()]
	for prime_power_combo in itertools.product(*powers):
		yield prod(prime_power_combo)
t = int(input(''))
for i in range(0, t):
	x = input('').split()
	x = [int(q) for q in x]
	n = x[0]
	k = x[1]
	qwe = []
	if n <= k:
		shovel = 1
	else:
		for q in get_divisors(n):
			qwe.append(q)
		qwe.sort(reverse=True)
		for z in qwe:
			if z <= k:
				shovel = int(n / z)
				break
	print(shovel)


mod = int(1000000000.0) + 7

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

def Ip():
	return map(int, input().split())
from math import sqrt
for _ in range(0, int(input())):
	(n, k) = Ip()
	s = int(sqrt(n)) + 2
	ans = 1
	for i in range(1, s):
		if i > k:
			break
		elif n % i == 0:
			ans = max(ans, i)
			t = n // i
			if t <= k:
				ans = max(ans, t)
	print(n // ans)


import math
t = int(input())
for i in range(t):
	s = input().split()
	n = int(s[0])
	k = int(s[1])
	if k >= n:
		print('1')
		continue
	elif n % k == 0:
		print(n // k)
		continue
	else:
		flag = 0
		p = 1
		while p <= n // p + 1 and p <= k:
			if n % p == 0:
				a = p
				b = n // p
				if b <= k:
					flag = 1
					break
				elif a <= k:
					ti = a
					a = b
					b = ti
			p += 1
		print(a)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	no = 10 ** 18
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if n / i <= k:
				no = min(no, i)
			if i <= k:
				no = min(no, n / i)
	print(int(no))


import sys
from math import sqrt
input = sys.stdin.readline
f = lambda : list(map(int, input().split()))
res = []
for _ in range(int(input())):
	(n, k) = f()
	ans = n
	for i in range(1, int(sqrt(n)) + 1):
		if i > k:
			break
		if n % i == 0:
			ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
	res.append(ans)
print('\n'.join(map(str, res)))


import math
t = int(input())
for s in range(0, t, 1):
	arr = list(map(int, input().split(' ')))
	n = arr[0]
	k = arr[1]
	if n <= k:
		print(1)
	else:
		ma = 1
		for i in range(2, int(math.sqrt(n)) + 1, 1):
			if n % i == 0:
				if n // i > ma and n // i <= k:
					ma = int(n / i)
				if i > ma and i <= k:
					ma = i
		print(n // ma)


import sys
import math
from collections import defaultdict

def factors(n, k):
	res = n
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			q1 = i
			q2 = n // i
			if n // q1 <= k:
				res = min(res, q1)
			if n // q2 <= k:
				res = min(res, q2)
	return res

def solve(test):
	(n, k) = map(int, input().split())
	ans = factors(n, k)
	print(ans)
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


from math import sqrt

def divisors(n):
	large_divisors = []
	for i in range(1, int(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 int(divisor)

def d():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		candidatos = set()
		if n < k or n == k:
			print(1)
			continue
		for divisor in divisors(max(n, k)):
			if divisor > k:
				continue
			candidatos.add(n // divisor)
		if len(candidatos) == 2 and 1 in candidatos and (n in candidatos):
			print(n)
			continue
		print(min(candidatos))
d()


import os
import sys
from io import BytesIO, IOBase

def solution(n, k):
	if k >= n:
		write(1)
		return
	if k == 1 or n == 1:
		write(n)
		return
	factors = []
	for i in range(1, n + 1):
		if i * i <= n:
			if n % i == 0:
				(f1, f2) = (i, n // i)
				factors.append(f1)
				if f1 != f2:
					factors.append(f2)
		else:
			break
	factors.sort(reverse=True)
	l = len(factors)
	for i in range(l):
		if factors[i] <= k:
			res = n // factors[i]
			write(res)
			return

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()


import math

def solve(n, k):
	sq = math.sqrt(n)
	mm = 1
	for i in range(1, int(sq) + 5):
		if n % i == 0 and n // i <= k:
			return i
		if n % i == 0 and i <= k:
			mm = i
	return n // mm
t = int(input())
for i_t in range(t):
	[n, k] = list(map(int, input().split(' ')))
	print(solve(n, k))


import sys
input = sys.stdin.readline
t = int(input())
for t1 in range(t):
	(n, k) = list(map(int, input().split(' ')))
	count = 0
	if n <= k:
		print(1)
	else:
		z = int(n ** 0.5) + 2
		fact = []
		val = 10000000000000000
		for i in range(z, 0, -1):
			if n % i == 0 and n // i <= k and (n // i >= 1):
				val = min(val, i)
			if n % i == 0:
				temp = n // i
				if n % temp == 0 and n // temp <= k and (n // temp >= 1):
					val = min(val, temp)
		print(val)


def task(n, k):
	if n <= k:
		print(1)
		return
	best = 1000000000
	for i in range(2, min(31623, k + 1)):
		if n % i == 0:
			div = n // i
			if div <= k:
				best = min(best, i)
			else:
				best = min(best, div)
	if best != 1000000000:
		print(best)
	else:
		print(n)
t = int(input())
for i in range(0, t):
	(n, k) = map(int, input().split())
	task(n, k)


from math import sqrt

def main():
	t = int(input())
	for __ in range(t):
		(a, b) = map(int, input().split())
		if a <= b:
			print(1)
		else:
			n = int(sqrt(a))
			ans = a
			for i in range(2, n + 1):
				if a % i == 0:
					if i <= b:
						ans = min(ans, a // i)
					if a // i <= b:
						ans = min(ans, i)
			print(ans)
main()


import math

def solve(n, k):
	if n <= k:
		print(1)
	else:
		m = int(n ** 0.5 + 1)
		ans = n
		for i in range(1, m):
			if n % i == 0:
				j = n // i
				if j <= k:
					ans = min(ans, i)
				if i <= k:
					ans = min(ans, j)
		print(ans)
for i in range(int(input())):
	(n, k) = map(int, input().split())
	solve(n, k)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	elif k == 1:
		print(n)
	else:
		j = 1
		mx = 1
		while j * j <= n:
			if n % j == 0:
				if n // j <= k:
					mx = max(mx, n // j)
				if j <= k:
					mx = max(mx, j)
			j += 1
		print(n // mx)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	m = 1000000000.0 + 1
	if n == k:
		print(1)
	elif n < k:
		print(1)
	else:
		for i in range(math.floor(math.sqrt(n)) + 1, 1, -1):
			if n % i == 0 and i <= k:
				m = min(n // i, m)
				if n % (n // i) == 0 and n // i <= k:
					m = min(n // (n // i), m)
		if m == 1000000000.0 + 1:
			print(n)
		else:
			print(m)


def demi(n, k):
	mini = n
	i = 2
	while i * i <= n:
		if n % i == 0:
			if i <= k:
				mini = min(mini, n // i)
			if n // i <= k:
				mini = min(mini, i)
		i += 1
	return mini
t = int(input())
while t:
	t -= 1
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if k >= n:
		print('1')
		continue
	print(demi(n, k))


from math import sqrt

def bt(arr, n, key):
	left = 0
	right = n
	mid = 0
	while left < right:
		mid = (right + left) // 2
		if arr[mid] == key:
			while mid + 1 < n and arr[mid + 1] == key:
				mid += 1
			break
		elif arr[mid] > key:
			right = mid
		else:
			left = mid + 1
	while mid > -1 and arr[mid] > key:
		mid -= 1
	return mid + 1

def ps(n):
	a = []
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				a.append(i)
			else:
				a.append(i)
				a.append(n // i)
	return sorted(a)
for zx in range(int(input())):
	(n, k) = map(int, input().split())
	s = ps(n)
	y = bt(s, len(s), k)
	r = s[y - 1]
	print(n // r)


from math import sqrt

def cal(n, k):
	Div = set()
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			Div.add(n // i)
			Div.add(i)
	output = n
	for a in Div:
		if a <= k:
			output = min(output, n // a)
	return output

def main():
	t = int(input())
	ans = []
	for i in range(t):
		(n, k) = map(int, input().split())
		ans.append(cal(n, k))
	for i in range(t):
		print(ans[i])
main()


testing_mode = True
import sys, traceback
test_data = ''
final_output = ''

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for x in range(multi)]
	else:
		next_line = next(test_data, None).strip() if test_data else sys.stdin.readline()
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = next_line.split()
		elif input_format == 4:
			formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
		elif input_format == 5:
			formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
		else:
			formatted_input = [next_line]
		return formatted_input if len(formatted_input) > 1 else formatted_input[0]

def log(*args):
	if testing_mode:
		print(*args)

def out(output_line, output_format=0, newline=True):
	global final_output
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 1:
		formatted_output = '\n'.join(map(str, output_line))
	if testing_mode:
		final_output += formatted_output + '\n' * newline
	else:
		print(formatted_output, end='\n' if newline else '')
test_inputs = ['\n5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733\n\n', '\n1\n1 1\n', '\n$$$\n', '\n$$$\n']
test_outputs = ['\n2\n8\n1\n999999733\n1\n\n', '\n$$$\n', '\n$$$\n', '\n$$$\n']
import math

def solve():
	f = input(1, input(1))
	for (n, k) in f:
		factors = []
		for i in range(1, math.ceil(n ** 0.5) + 1):
			if n % i == 0:
				factors.append((i, n // i))
		for (i, j) in reversed(factors):
			factors.append((j, i))
		log(n, k)
		log(factors)
		for i in range(len(factors)):
			if factors[i][0] > k:
				out(factors[i - 1][1])
				break
		else:
			out(factors[-1][1])
	return

def run_all(overwrite_testing=False):
	global testing_mode, final_output, test_data
	testing_mode = overwrite_testing and testing_mode
	if testing_mode:
		tests_failed = 0
		for (test_number, (test_in, test_out)) in enumerate(zip(test_inputs, test_outputs)):
			final_output = ''
			if test_in.lstrip()[:3] == '$$$':
				continue
			test_data = iter([i for i in test_in.split('\n') if i])
			print(f'Test Case #{test_number + 1}:')
			print('<' * 20)
			fail = False
			verdict = '\x1b[92m\x1b[1mPASS\x1b[0m'
			try:
				solve()
				final = final_output.rstrip('\n')
				raw_out = iter(map(str, final.split('\n'))) if final else iter(())
			except Exception:
				raw_out = ''
				fail = True
				print('\x1b[95m')
				traceback.print_exc()
				print('\x1b[0m')
			if raw_out:
				if test_out.lstrip()[:3] == '$$$':
					verdict = '\x1b[94m\x1b[1mSKIP\x1b[0m'
					print('\x1b[94m' + '\n'.join(list(raw_out)) + '\x1b[0m')
				else:
					for line_out in [i for i in test_out.split('\n') if i]:
						line_raw = next(raw_out, '% None %')
						if line_raw == line_out.strip():
							print(f'\x1b[92m{line_raw}\x1b[0m')
						else:
							print(f'\x1b[91m{line_raw}\x1b[0m')
							fail = True
					line_raw = next(raw_out, None)
					while line_raw:
						print(f'\x1b[91m{line_raw}\x1b[0m')
						line_raw = next(raw_out, None)
						fail = True
			print('>' * 20)
			if fail:
				verdict = '\x1b[91m\x1b[1mFAIL\x1b[0m'
				tests_failed += 1
			print(verdict + '\n')
		if tests_failed:
			print(f"\x1b[91m\x1b[1m{tests_failed} TEST{('S' if tests_failed > 1 else '')} FAILED!\x1b[0m")
		else:
			print(f'\x1b[92m\x1b[1mALL TESTS PASSED!\x1b[0m')
	else:
		test_data = False
		solve()
run_all(False)


from math import sqrt

def Factor(n):
	res = []
	for x in range(1, int(sqrt(n) + 1)):
		if n % x == 0:
			res.append(x)
	return res
t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	if k >= n:
		print(1)
	else:
		factor = Factor(n)
		for j in range(len(factor)):
			if int(n / factor[j]) not in factor:
				factor.append(int(n / factor[j]))
		factor.sort()
		for j in range(len(factor)):
			if n / factor[j] <= k:
				print(factor[j])
				break


from sys import stdin, stdout
import math
cin = stdin.readline
cout = stdout.write
for _ in range(int(cin())):
	(n, k) = map(int, cin().split())
	if k >= n:
		cout('1\n')
		continue
	s = 10 ** 12
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			if k >= n // i:
				s = min(s, i)
			elif k >= i:
				s = min(s, n // i)
	if s < 10 ** 12:
		cout(str(s) + '\n')
	else:
		cout(str(n) + '\n')


def factors(x, k):
	result = []
	i = 1
	while i * i <= x:
		if x % i == 0 and i <= k:
			result.append(i)
			if x // i != i and x // i <= k:
				result.append(x // i)
		i += 1
	return result
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	if n <= k:
		print(1)
	elif n > k:
		p1 = factors(n, k)
		print(n // max(p1))


t = int(input())
from math import sqrt
import bisect
for _ in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		root = int(sqrt(n))
		divs = []
		for x in range(1, root + 1):
			if n % x == 0:
				divs.append(x)
				divs.append(n // x)
		divs.sort()
		ans = bisect.bisect_right(divs, k) - 1
		print(n // divs[ans])


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)))
l = int(input())
m = 1
for i in range(l):
	(c, k) = map(int, input().split())
	a = factors(c)
	for t in a:
		if m < t and t <= k:
			m = t
	print(int(c / m))
	m = 1


a = input()
for x in range(int(a)):
	b = input().split(' ')
	ans = int(b[0])
	n = int(b[0])
	k = int(b[1])
	for i in range(1, int(n ** 0.5) + 1):
		if n % i != 0:
			continue
		if i <= k:
			ans = min(ans, n // i)
		if n // i <= k:
			ans = min(ans, i)
	print(ans)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	d = n
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			q = n // i
			if i <= k:
				d = min(d, q)
			if q <= k:
				d = min(d, i)
	print(d)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	i = 1
	o = k
	while i * i <= n:
		if n % i == 0:
			if n // i <= k:
				o = i
				break
			if i > k:
				break
			o = n // i
		i += 1
	print(o)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		ans = 1
		i = 1
		while i * i <= n:
			if i > k:
				break
			if n % i == 0:
				ans = max(ans, i)
				if n // i <= k:
					ans = max(ans, n // i)
			i += 1
		print(n // ans)


def get_factors(num):
	l = [1, num]
	for i in range(2, int(num ** 0.5) + 1):
		if not num % i:
			if i not in l:
				l.append(i)
				if num // i not in l:
					l.append(num // i)
	return l
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().rstrip().split(' '))
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		z = get_factors(n)
		r = [i for i in z if i in range(k + 1)]
		print(n // max(r))


t = int(input())
for loop in range(t):
	(n, k) = map(int, input().split())
	ans = n
	for i in range(1, k + 1):
		if i * i > n:
			break
		if n % i != 0:
			continue
		j = n // i
		if i <= k:
			ans = min(ans, j)
		if j <= k:
			ans = min(ans, i)
	print(ans)


for i in ' ' * int(input()):
	(n, k) = map(int, input().split())
	dividers = []
	d = 1
	while d * d <= n:
		if n % d == 0:
			if d == n // d:
				dividers.append(d)
			else:
				dividers.append(d)
				dividers.append(n // d)
		d += 1
	while max(dividers) > k:
		dividers.remove(max(dividers))
	print(n // max(dividers))


from sys import stdin, stdout

def find(K, N):
	r = 1
	for i in range(1, min(int(K ** 0.5), N) + 1):
		if K % i == 0:
			if K // i <= N:
				return i
			r = i
	return K // r

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


rw = int(input())
for eqw in range(rw):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	d = []
	for i in range(2, int(n ** 0.5) + 2):
		if n % i == 0:
			d.append(i)
	d.reverse()
	if len(d) == 0:
		print(n)
		continue
	dn = []
	for i in d:
		if n // i <= k:
			dn.append(i)
		if i <= k:
			dn.append(n // i)
	if len(dn) != 0:
		print(min(dn))
	else:
		print(n)


t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	if a <= b:
		print(1)
	elif b == 1:
		print(a)
	else:
		k = a
		i = 1
		while i * i <= a:
			if a % i == 0:
				if i <= b:
					k = min(k, a // i)
				if a // i <= b:
					k = min(k, i)
			i += 1
		print(k)
	t -= 1


import sys
import math
q = int(sys.stdin.readline())
for _ in range(q):
	maxVal = -sys.maxsize
	(n, k) = map(int, sys.stdin.readline().split())
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i <= k and n / i <= k:
				maxVal = max(maxVal, i, n / i)
			elif i <= k:
				maxVal = max(maxVal, i)
			elif n / i <= k:
				maxVal = max(maxVal, n / i)
	print(int(n / maxVal))


import math

def isprime(n):
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True
n = int(input())
for t in range(n):
	b = input().split()
	(n, k) = (int(b[0]), int(b[1]))
	if isprime(n) and k < n:
		print(n)
	elif isprime(n) and k >= n:
		print(1)
	elif k >= n:
		print(1)
	else:
		o = n
		for i in range(1, int(math.sqrt(n)) + 1):
			if n % i == 0:
				if i <= k:
					o = min(o, n // i)
				if n // i <= k:
					o = min(o, i)
		print(o)


from math import gcd
for i in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n
	for i in range(1, min(int(n ** 0.5) + 1, k) + 1):
		if n % i == 0:
			ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, n // (n // i))
	print(ans)


import sys
input = sys.stdin.readline

def solve():
	(n, k) = map(int, input().split())
	RESULT = 10000000000
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			x = n // i
			y = i
			if x <= k and y > k:
				RESULT = min(RESULT, y)
			elif x > k and y <= k:
				RESULT = min(RESULT, x)
			elif x <= k and y <= k:
				RESULT = min(RESULT, min(x, y))
	print(RESULT)
for _ in range(int(input())):
	solve()


from sys import stdin, stdout
import math

def main():
	t = int(stdin.readline())
	MX = 1000000000.0 + 1
	prime = [2]
	for i in range(3, math.ceil(math.sqrt(MX)), 2):
		is_prime = True
		for x in prime:
			if i % x == 0:
				is_prime = False
				break
			if x > math.ceil(math.sqrt(i)):
				break
		if is_prime:
			prime.append(i)
	for _ in range(t):
		(n, k) = list(map(int, stdin.readline().split()))
		if k >= n:
			stdout.write('1\n')
			continue
		is_prime = True
		ans = int(10000000000.0)
		for x in range(math.ceil(math.sqrt(n)), 0, -1):
			if n % x == 0:
				if k >= n / x:
					ans = x
				elif k >= x:
					ans = min(ans, int(n / x))
		stdout.write(str(ans) + '\n')
main()


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

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 solve(n, k):
	if k >= n:
		return 1
	D = make_divisors(n)
	ans = n
	for d in D:
		if d <= k:
			ans = min(ans, n // d)
	return ans

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
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)))
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		(n, k) = list(map(int, input().split()))
		factorino = list(factors(n))
		factorino.sort(reverse=True)
		for kap in factorino:
			if kap <= k:
				yield (n // kap)
				break
t = int(input())
ans = gift()
print(*ans, sep='\n')


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

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	(n, k) = read_ints()
	i = 1
	largest = 1
	while i * i <= n:
		if n % i == 0:
			if i <= k:
				largest = max(largest, i)
			if n // i <= k:
				largest = max(largest, n // i)
		i += 1
	print(n // largest)


def factors(x):
	result = []
	i = 1
	while i * i <= x:
		if x % i == 0:
			result.append(i)
			if x // i != i:
				result.append(x // i)
		i += 1
	return result
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		r = factors(n)
		r.sort()
		k1 = k
		i = 0
		while k1 >= r[i]:
			if k < r[i + 1] and k >= r[i]:
				c = r[i]
				break
			i += 1
		d = n / c
		print(int(d))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	ans = float('inf')
	ans = n
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			if i <= k:
				ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, n // (n // i))
	print(ans)


import sys
import math as mt
input = sys.stdin.buffer.readline
t = int(input())

def printDivisors(n, maxi1):
	i = 1
	ch = 0
	maxi = 1
	while i <= mt.sqrt(n):
		if n % i == 0:
			if n / i == i:
				if i <= maxi1:
					maxi = max(i, maxi)
			else:
				if i <= maxi1:
					maxi = max(i, maxi)
				if n // i <= maxi1:
					maxi = max(n // i, maxi)
		i = i + 1
	return maxi
for __ in range(t):
	(n, k) = map(int, input().split())
	d = printDivisors(n, k)
	print(n // d)


def factorize(n):
	factors = []
	for i in range(1, min(int(n ** 0.5), k) + 1):
		if n % i == 0:
			factors.append(i)
			if n // i <= k:
				factors.append(n // i)
	return sorted(factors, reverse=True)
import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	factors = factorize(n)
	for f in factors:
		if n % f == 0:
			print(n // f)
			break


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = n
	for i in range(1, n + 1):
		if i * i > n:
			break
		if n % i == 0:
			if i <= k:
				a = min(a, n // i)
			if n // i <= k:
				a = min(a, i)
	print(a)


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

def factor(n, k):
	i = 1
	s = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				if i <= k:
					s.append(i)
			else:
				if i <= k:
					s.append(i)
				if n // i <= k:
					s.append(n // i)
		i = i + 1
	sr = sorted(s)
	if sr[-1] == n:
		return sr[-2]
	else:
		return sr[-1]
for _ in range(t):
	(n, k) = inp()
	if n <= k:
		print(1)
		continue
	if n % k == 0:
		print(n // k)
	else:
		print(n // factor(n, k))


from math import ceil, sqrt
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		i = 2
		flag = 0
		p = []
		while i <= int(sqrt(n)) and i <= k:
			if n % i == 0:
				flag = 1
				p.append(i)
			i += 1
		if flag == 0:
			print(n)
		else:
			c = 0
			for i in range(len(p)):
				if n // p[i] <= k:
					print(p[i])
					c = 1
					break
			if c == 0:
				print(n // p[-1])


t = int(input())
for _ in range(t):
	ans = True
	(need, n) = list(map(int, input().split()))
	sqrt = int(need ** 0.5) + 2
	div = []
	for i in range(1, sqrt):
		if need % i == 0:
			div.append(i)
			div.append(need // i)
	div.sort(reverse=True)
	for i in div:
		if i <= n:
			print(need // i)
			break


import sys
import collections as cc
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n, k) = I()
	ans = n
	temp = set()
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			x = i
			y = n // i
			if x <= k:
				ans = min(ans, n // x)
			if y <= k:
				ans = min(ans, n // y)
	print(ans)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	flag = 0
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0 and n / i <= k:
			print(i)
			flag = 1
			break
	if flag == 0:
		m = 10000000000
		for i in range(1, int(math.sqrt(n)) + 1):
			if n % i == 0 and i <= k:
				m = min(m, n // i)
		print(m)


import math

def g(x, q, k):
	for i in range(k + 1, math.ceil(math.sqrt(x)) + 1):
		if x % i == 0:
			r = x // i
			if r >= q:
				continue
			return (r, i)
	return (1, a)
num = int(input())
for _ in range(num):
	(a, b) = [int(i) for i in input().split()]
	if a <= b:
		print(1)
		continue
	min_ = 1e+19
	(gcd, i) = g(a, a, 1)
	if i <= b:
		min_ = min(min_, a // i)
	while gcd > b and gcd > 1:
		(gcd, i) = g(a, gcd, i)
		if i <= b:
			min_ = min(min_, a // i)
	t = a // gcd
	if min_ < t:
		print(min_)
	else:
		print(t)


def main():
	t = int(input())
	for i in range(t):
		nums = list(map(int, input().split()))
		j = 1
		n = nums[0]
		k = nums[1]
		facs = []
		facs2 = []
		done = False
		while j * j <= n:
			if n % j == 0:
				facs.append(j)
				facs2.append(n // j)
			j += 1
		facs2.reverse()
		facs.extend(facs2)
		for fac in facs:
			num_per_package = n // fac
			if num_per_package <= k:
				print(fac)
				break
main()


import math
T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	ans = n
	ans1 = n
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n // i <= k:
				ans = i
				break
			elif i <= k:
				ans1 = min(ans1, n // i)
	print(min(ans, ans1))


import math

def div(n, k):
	i = 1
	l = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				if i <= k:
					l.append(i)
			else:
				if i <= k:
					l.append(i)
				if n / i <= k:
					l.append(n // i)
		i = i + 1
	return l

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
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print('1')
	elif n & 1 and isprime(n):
		print(n)
	else:
		l = div(n, k)
		print(n // max(l))


T = int(input())
for x in range(1, T + 1):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		deler_max = 1
		for i in range(1, int(n ** (1 / 2)) + 1):
			if n % i == 0:
				j = n // i
				if i <= k:
					deler_max = max(deler_max, i)
				if j <= k:
					deler_max = max(deler_max, j)
		print(n // deler_max)


import math
for x in range(int(input())):
	(h, m) = list(map(int, input().split()))
	k = []
	for i in range(1, int(math.sqrt(h)) + 1):
		if h % i == 0:
			k.append(i)
			k.append(h // i)
	k.sort()
	p = h
	for i in range(len(k)):
		if k[i] <= m:
			p = h // k[i]
	print(p)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print('1')
	elif int(n ** 0.5) + 1 > k:
		maxi = 0
		for j in range(1, k + 1):
			if n % j == 0:
				maxi = max(maxi, j)
		print(n // maxi)
	else:
		maxi = 0
		for j in range(1, int(n ** 0.5) + 1):
			if n % j == 0:
				maxi = max(maxi, j)
				a = n // j
				if a <= k:
					maxi = max(maxi, a)
		print(n // maxi)


import math
t = int(input())
for _ in range(t):
	count = 0
	ans = 10 ** 9
	(n, k) = map(int, input().split())
	for i in range(1, round(math.sqrt(n)) + 1):
		if n % i == 0:
			count += 1
	if count == 1 and n > k or k == 1:
		print(n)
	elif n <= k:
		print(1)
	elif n > k and count != 1:
		for i in range(1, round(math.sqrt(n)) + 1):
			if n % i == 0 and i <= k:
				ans = min(n / i, ans)
			if n % i == 0 and n / i <= k:
				ans = min(ans, i)
		print(int(ans))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print('1')
	else:
		flag = True
		maxx = 0
		for i in range(1, int(math.sqrt(n)) + 1):
			if i > k:
				break
			elif n % i == 0:
				if n // i <= k:
					print(i)
					flag = False
					break
				else:
					maxx = max(maxx, i)
		if flag:
			print(n // maxx)


import sys
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass

def factors(n):
	ans = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			ans.append(i)
			ans.append(n // i)
	return ans
input = sys.stdin.readline
for tt in range(int(input())):
	(n, k) = map(int, input().split())
	l = factors(n)
	l.sort(reverse=True)
	for i in l:
		if i <= k:
			print(n // i)
			break


for t_ in range(int(input())):
	(n, k) = map(int, input().split())
	i = 1
	ans = n
	while i * i <= n:
		if n % i:
			i += 1
			continue
		if i <= k:
			ans = min(ans, n // i)
		if n // i <= k:
			ans = min(ans, i)
		i += 1
	print(ans)


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 solve():
	(n, k) = li()
	s = int(math.sqrt(n)) + 1
	ans = []
	for i in range(1, s):
		if n % i == 0:
			if n / i != i:
				ans.append(i)
				ans.append(n // i)
			else:
				ans.append(i)
	ans.sort(reverse=True)
	p = k
	for i in ans:
		if i <= k:
			print(n // i)
			return
for _ in range(I()):
	solve()


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


import math

def pf(x):
	r = []
	while x % 2 == 0:
		r.append(2)
		x //= 2
	for i in range(3, int(math.sqrt(x)) + 1, 2):
		while x % i == 0:
			r.append(i)
			x //= i
	if x > 2:
		r.append(2)
	return r

def prime(x):
	r = []
	if x == 2:
		return True
	elif x == 3:
		return True
	for i in range(2, int(math.sqrt(x)) + 1):
		if x % i == 0:
			return False
	return True
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif prime(n):
		print(n)
	else:
		r = []
		for i in range(1, int(math.sqrt(n)) + 1):
			if n % i == 0:
				if n // i == i:
					r.append(i)
				else:
					r.append(i)
					r.append(n // i)
		r.sort()
		maxx = 0
		for i in r:
			if i > k:
				break
			else:
				maxx = max(maxx, i)
		print(n // maxx)


import math
from bisect import bisect_right as bs

def p1(n, k):
	p = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if i > k:
			break
		if n % i == 0:
			p.append(i)
			p.append(n // i)
	return sorted(list(p))
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	d = p1(n, k)
	id = bs(d, k) - 1
	print(n // d[id])


import sys
from collections import defaultdict as dd

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
from math import *
import copy
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())

def bo(i):
	return ord(i) - ord('a')
t = fi()
while t > 0:
	t -= 1
	(n, k) = mi()
	if k >= n:
		print(1)
		continue
	f = 0
	d = []
	for i in range(2, int(sqrt(n)) + 2):
		if n % i == 0:
			d.append(i)
			d.append(n // i)
	d.sort()
	for i in range(len(d)):
		if n // d[i] <= k:
			print(d[i])
			f = 1
			break
	if f == 0:
		print(n if k < n else 1)


def divisors(N):
	U = int(N ** 0.5) + 1
	L = [i for i in range(1, U) if N % i == 0]
	return L + [N // i for i in reversed(L) if N != i * i]
(T, *NK) = map(int, open(0).read().split())
for (n, k) in zip(*[iter(NK)] * 2):
	D = divisors(n)
	print(min((n // d for d in D if d <= k)))


t = int(input())
for y in range(t):
	(n, k) = map(int, input().split())
	if k < n ** (1 / 2):
		for i in range(k, 0, -1):
			if n % i == 0:
				print(n // i)
				break
	elif k < n:
		(p, m) = (0, 1)
		for j in range(2, int(n ** (1 / 2) + 1)):
			if n % j == 0:
				m = j
				if j >= n / k:
					p = j
					break
		if p >= n / k:
			print(p)
		else:
			print(n // m)
	else:
		print(1)


import math
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	factors = []
	min_val = x
	for i in range(1, int(math.sqrt(x) + 1)):
		if x % i == 0:
			val_1 = i
			val_2 = x // i
			if val_1 <= y:
				if min_val >= val_1:
					min_val = val_2
			if val_2 <= y:
				if min_val >= val_2:
					min_val = val_1
	print(min_val)


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())
from collections import Counter
from math import gcd

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors
for case in range(itg()):
	(n, k) = mpint()
	factors = distinct_factors(n)
	for fac in sorted(factors, reverse=True):
		if fac <= k:
			print(n // fac)
			break


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, deque
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()
		if k >= n:
			print(1)
		else:
			res = INF
			for i in range(1, int(sqrt(n)) + 1):
				if n % i == 0:
					if n // i <= k:
						res = min(res, i)
					if i <= k:
						res = min(res, n // i)
			print(res)
main()


import math
t = int(input())
while t:
	t = t - 1
	minn = 1999999999
	(n, k) = map(int, input().split())
	rt = int(math.sqrt(n))
	for i in range(1, rt + 1, 1):
		if n % i == 0:
			if n / i <= k:
				minn = min(minn, i)
			if i <= k:
				minn = min(minn, n / i)
	print(int(minn))


def factors(x):
	result = list()
	i = 1
	while i * i <= x:
		if x % i == 0:
			result.append(i)
			if x // i != i:
				result.append(x // i)
		i += 1
	return result
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		arr = factors(n)
		arr.sort()
		for i in range(len(arr) - 1, -1, -1):
			if arr[i] <= k:
				deno = arr[i]
				break
		print(n // deno)


from math import sqrt

def factor(n, k):
	a = [1, n]
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			a.append(i)
			a.append(n // i)
	a.sort()
	return a
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = factor(n, k)
	i = 0
	while i < len(a) and a[i] <= k:
		i += 1
	i -= 1
	print(n // a[i])


import math

def solve(n, k):
	ans = n
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i <= k:
				ans = min(ans, n / i)
			if n / i <= k:
				ans = min(ans, i)
	print(int(ans))
	return
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	solve(n, k)


T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	if k >= n:
		print('1')
	else:
		l1 = []
		l2 = []
		i = 1
		sq = n ** 0.5
		while i <= sq:
			if n % i == 0:
				if n / i == i and i <= k:
					l1.append(i)
				else:
					if i <= k:
						l1.append(i)
					if n / i <= k:
						l2.append(n / i)
			i = i + 1
		if len(l1) == 0:
			a = 0
		else:
			a = l1[-1]
		if len(l2) == 0:
			b = 0
		else:
			b = l2[0]
		m = max(a, b)
		print(int(n / m))


from math import ceil, sqrt, log2, floor, pi
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	if K >= N:
		print(1)
		continue
	flag = 1
	Prev = N
	for i in range(1, int(ceil(sqrt(N))) + 1):
		if N % i == 0:
			Num = int(N / i)
			if Num <= K:
				print(int(N / Num))
				flag = 0
				break
			if N / Num <= K:
				Prev = Num
	if flag:
		print(Prev)


from math import sqrt
t = int(input())
for q in range(0, t):
	(n, k) = map(int, input().split())
	ans = 0
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0 and i <= k:
			ans = max(ans, i)
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			if n // i <= k:
				ans = max(ans, n // i)
	print(n // ans)


import random
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	min_now = n
	for i in range(1, min(k + 1, int(n ** 0.5) + 2)):
		if n % i == 0:
			if n // i <= k:
				min_now = min(min_now, i)
				break
			min_now = min(min_now, n // i)
	print(min_now)


t = int(input())
for _ in range(t):
	inp = list(map(int, input().split()))
	n = inp[0]
	k = inp[1]
	if k >= n:
		print(1)
		continue
	if k == 1:
		print(n)
		continue
	else:
		maxz = 1
		for i in range(2, int(pow(n, 0.5)) + 1):
			if n % i == 0:
				if i <= k:
					maxz = max(maxz, i)
				if n // i <= k:
					maxz = max(maxz, n // i)
		print(n // maxz)


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((n - 1) // k + 1, int(sqrt(n) + 1)):
			if n % i == 0:
				print(i)
				return
		for i in range(min(k, int(sqrt(n) + 1)), 0, -1):
			if n % i == 0:
				print(n // i)
				return
		print(n)
	q = int(input())
	for _ in range(q):
		solve()
main()


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 1
	if n <= k:
		print(1)
	else:
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				if i <= k:
					ans = max(ans, i)
				if n // i <= k:
					ans = max(ans, n // i)
		print(n // ans)


testcases = int(input())
import math
for testcase in range(testcases):
	newarr = input()
	newarr = newarr.split()
	n = int(newarr[0])
	k = int(newarr[1])
	if k >= n:
		print(1)
		continue
	if n % k == 0:
		print(n // k)
		continue
	if k == 2 and n & 1 == 1:
		print(n)
		continue
	if k == 3 and n & 1 == 0:
		print(n // 2)
		continue
	sqrtans = int(math.sqrt(n)) + 3
	ans = n
	for i in range(2, min(k + 1, sqrtans)):
		if n % i == 0:
			ans = n // i
			if ans <= k:
				ans = i
				break
	print(ans)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	t = a
	c = []
	if b >= a:
		print(1)
	else:
		for i in range(1, int(math.sqrt(a)) + 1):
			if a % i == 0:
				c.append(i)
				c.append(a // i)
		for i in range(len(c)):
			if c[i] <= b:
				t = min(a // c[i], t)
		print(t)


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))

def IF(c, t, f):
	return t if c else f

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:
				d[c] += 1
				n //= c
			if n < 2:
				break
		if n > 1:
			d[n] += 1
		return d.items()

	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 main():
	t = I()
	rr = []
	pr = Prime(10 ** 10)
	for _ in range(t):
		(n, k) = LI()
		if n <= k:
			rr.append(1)
		else:
			ds = pr.divisions(n)
			for d in sorted(ds):
				if n // d <= k:
					rr.append(d)
					break
	return JA(rr, '\n')
print(main())


from math import floor
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n
	if k >= n:
		print(1)
	elif k >= n // 2 and (not n & 1):
		print(2)
	else:
		for j in range(2, min(k, floor(n ** 0.5)) + 1):
			if n % j == 0:
				div = n // j
				ans = min(ans, div, j if div <= k else n)
		print(ans)


import sys
from bisect import bisect
from math import sqrt, floor, factorial, gcd
from collections import deque, Counter, defaultdict
inp = sys.stdin.readline
read = lambda : list(map(int, inp().strip().split()))

def a():
	ans = ''
	for _ in range(int(inp())):
		(a, b) = read()
		i = 1
		while i < max(max(a, b), min(a, b) * 2) or i ** 2 < a * b * 2:
			i += 1
		ans += str(i ** 2) + '\n'
	print(ans)

def b():
	ans = ''
	for _ in range(int(inp())):
		n = int(inp())
		arr = sorted(read())
		x = 10 ** 9
		for i in range(n - 1):
			x = min(x, abs(arr[i] - arr[i + 1]))
		ans += str(x) + '\n'
	print(ans)

def c():
	ans = ''
	for _ in range(int(inp())):
		n = int(inp())
		arr = read()
		odd_set = []
		even_set = []
		for i in arr:
			if i % 2:
				odd_set.append(i)
			else:
				even_set.append(i)
		if len(even_set) % 2 == 0 and len(odd_set) % 2 == 0:
			ans += 'YES\n'
			continue
		elif len(even_set) % 2 == 1 and len(odd_set) % 2 == 1:
			flag = 0
			for i in odd_set:
				if i + 1 in even_set or i - 1 in even_set:
					ans += 'YES\n'
					flag = 1
					break
			if flag:
				continue
			else:
				ans += 'NO\n'
		else:
			ans += 'NO\n'
	print(ans)

def printDivisors(n):
	ans = []
	i = 1
	while i <= sqrt(n):
		if n % i == 0:
			if n / i == i:
				ans.append(i)
			else:
				ans.extend([i, n // i])
		i = i + 1
	return sorted(ans)

def d():
	ans = ''
	for _ in range(int(inp())):
		(n, k) = read()
		if n <= k:
			ans += str(1) + '\n'
			continue
		divs = printDivisors(n)
		ind = bisect(divs, k)
		ans += str(n // divs[ind - 1]) + '\n'
	print(ans)
d()


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	m = n
	for i in range(1, min(int(n ** 0.5 + 3), k + 1)):
		if n % i == 0:
			if n // i <= k:
				m = min(m, i, k)
			else:
				m = min(m, n // i)
	print(m)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		ans = 0
		factors = []
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				factors.append(i)
				factors.append(n // i)
		factors.sort()
		for i in factors:
			if i > k:
				print(n // ans)
				break
			else:
				ans = i


def primefact(n, k):
	d = []
	ans = []
	for i in range(1, min(k + 1, int(n ** 0.5) + 1)):
		if n % i == 0:
			d.append(i)
	for i in d:
		ans.append(n // i)
		if n // i <= k:
			ans.append(i)
	return min(ans)
for i in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		print(primefact(n, k))


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 gcd, ceil

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

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	(n, k) = map(int, input().split())
	ans = 1
	for i in range(1, int(n ** 0.5) + 69):
		if i > k:
			break
		if n % i == 0:
			ans = max(ans, i)
			if n // i <= k:
				ans = max(ans, n // i)
	print(n // ans)


import sys
import math

def prime(n, k):
	save = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if n // i <= k:
				return i
			if i <= k:
				save.append(i)
	if not len(save):
		return n
	return n // max(save)
t = int(sys.stdin.readline().strip())
for i in range(t):
	(n, k) = list(map(int, sys.stdin.readline().strip().split(' ')))
	if k >= n:
		print(1)
	else:
		p = prime(n, k)
		print(p)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().rstrip().split())
	if k == 1:
		print(n)
		continue
	if n <= k:
		print(1)
		continue
	fact = 1
	factorArray = []
	while fact <= int(math.sqrt(n)):
		if n % fact == 0:
			factorArray.append(fact)
			if n // fact != fact:
				factorArray.append(n // fact)
		fact += 1
	ans = 0
	factorArray.sort()
	for num in factorArray:
		if num <= k:
			ans = num
		else:
			break
	ans = n // ans
	print(ans)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ans = []
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			ans.append(i)
			ans.append(int(n / i))
	ans.sort()
	for element in ans:
		if n / element <= k:
			print(element)
			break


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	r = int(n ** 0.5) + 1
	a = -1
	for i in range(1, r + 1):
		if n % i == 0 and n // i <= k:
			a = i
			break
	if a == -1:
		for i in range(r + 1, 0, -1):
			if n % i == 0 and i <= k:
				a = n // i
				break
	print(a)


def solve(n, k, ans):
	facts = set()
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			facts.add(i)
			facts.add(n // i)
	facts = list(facts)
	facts.sort()
	max_k = 0
	for i in facts:
		if i <= k:
			max_k = i
	ans.append(n // max_k)
ans = []
for i in range(int(input())):
	(n, k) = map(int, input().split())
	solve(n, k, ans)
for i in ans:
	print(i)


testcase = int(input())
for test in range(testcase):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		ans = 10 ** 9 + 7
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				if i <= k and n / i > k:
					ans = min(ans, n // i)
				elif n / i <= k and i > k:
					ans = min(ans, i)
				elif n / i <= k and i <= k:
					ans = min(ans, min(i, n // i))
		print(ans)


from math import *
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lf = []
	z = int(sqrt(n))
	for i in range(1, z + 1):
		if n % i == 0:
			if i <= k:
				lf.append(i)
			if n // i <= k:
				lf.append(n // i)
	lf.sort()
	print(n // lf[-1])


from math import sqrt, floor
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = float('inf')
	for i in range(1, floor(sqrt(n)) + 1):
		if n % i == 0:
			x = i
			y = n // x
			if y <= k:
				ans = min(ans, x)
				break
			else:
				pass
			if x <= k:
				ans = min(ans, y)
			else:
				break
	print(ans)


import sys
lines = sys.stdin.readlines()
T = int(lines[0].strip())
for t in range(T):
	(n, k) = map(int, lines[t + 1].strip().split(' '))
	if k >= n:
		print(1)
		continue
	lower = (n - 1) // k + 1
	res = -1
	if lower <= k:
		for i in range(lower, int(n ** 0.5) + 2):
			if n % i == 0:
				res = i
				break
	if res == -1:
		for i in range(min(k, int(n ** 0.5) + 1), 0, -1):
			if n % i == 0:
				res = n // i
				break
	print(res)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n
	if k >= n:
		ans = 1
	else:
		for i in range(int(n ** 0.5), 1, -1):
			if n % i == 0:
				if n / i <= k and i < ans:
					ans = i
				elif i <= k and n // i < ans:
					ans = n // i
	print(ans)


import math

def fact(n):
	lst = []
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			lst.append(i)
			lst.append(n // i)
	return lst
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		lst = fact(n)
		lst.sort(reverse=True)
		for j in lst:
			if j <= k:
				print(n // j)
				break


import os
os_input = os.read(0, int(10000000.0)).split()
os_input_pos = -1

def cin():
	global os_input_pos
	os_input_pos += 1
	return os_input[os_input_pos]
T = int(cin())
res = []
while T:
	T -= 1
	(n, k) = (int(cin()), int(cin()))
	ans = n
	i = 1
	while i <= k and i * i <= n:
		if n % i == 0:
			ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
		i += 1
	res.append(str(ans).encode())
os.write(1, '\n'.encode().join(res))


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print('1')
	else:
		ans = 1
		q = int(math.sqrt(n))
		for i in range(1, q + 1):
			if n % i == 0:
				if i <= k:
					ans = max(ans, i)
				if n // i <= k:
					ans = max(ans, n // i)
		print(n // ans)


import math as m
a = int(input())
for _ in range(a):
	(b, c) = map(int, input().split())
	ma = 0
	for i in range(1, int(m.sqrt(b)) + 1):
		if b % i == 0:
			if int(b / i) == i:
				if i <= c:
					ma = max(ma, i)
			else:
				if int(i) <= c:
					ma = max(ma, i)
				if int(b / i) <= c:
					ma = max(ma, b / i)
	print(int(b / ma))


import sys
t = int(sys.stdin.readline())

def divisor(n):
	result = []
	for i in range(1, int(n ** 0.5) + 1):
		result.extend([i, n // i])
	return result
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	if n <= k:
		print(1)
		continue
	a = divisor(n)
	a.sort()
	for i in a:
		if n % i == 0:
			if n // i <= k:
				print(n // (n // i))
				break


for i in range(int(input())):
	(a, b) = map(int, input().split())
	q = int(a ** 0.5) + 1
	l = []
	while q > 0:
		if a % q == 0:
			if a // q == q:
				l.append(q)
			else:
				l.append(q)
				l.append(a // q)
		q -= 1
	l = sorted(l)[::-1]
	for o in l:
		if o <= b:
			print(a // o)
			break


import os
import sys
from io import BytesIO, IOBase
import bisect
inp = lambda : int(input())
inps = lambda : [int(x) for x in input().split()]

def main():
	for _ in range(inp()):
		(n, k) = inps()
		i = 2
		ans = 1
		if k >= n:
			print(1)
			continue
		while i * i <= n:
			if n % i == 0:
				if i <= k:
					ans = max(ans, i)
				if n // i <= k:
					ans = max(ans, n // i)
			i += 1
		print(n // 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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


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 sol(k, n):
	ans = inf
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			z1 = n // i
			z2 = i
			if z1 <= k:
				ans = min(ans, z2)
			if z2 <= k:
				ans = min(ans, z1)
	return ans
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	print(sol(k, n))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	(x, ans) = (int(n ** 0.5), n)
	for i in range(2, x + 2):
		if n % i == 0:
			if i <= k:
				if ans > n / i:
					ans = n / i
			if n / i <= k:
				if ans > i:
					ans = i
	print(int(ans))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ans = float('INF')
	for i in range(1, int(n ** 0.5) + 5):
		if i > k:
			break
		if n % i == 0:
			x = n // i
			ans = min(ans, x)
			if x <= k:
				ans = min(ans, i)
	print(ans)


import math

def div(n):
	global k
	b = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				b.append(i)
			else:
				b.append(i)
				b.append(n // i)
		i = i + 1
	ma = -1
	for i in b:
		if ma < i and i <= k:
			ma = i
	print(n // ma)
for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = n
	if k == 1:
		print(n)
		continue
	div(a)


n = int(input())
o = []
for i in range(n):
	(u, v) = [int(x) for x in input().split()]
	t = min(int(u ** 0.5), v)
	a = [1] * t
	b = []
	s = -1
	r = 1
	for i in range(t):
		if u % (i + 1) == 0:
			if u // (i + 1) <= v:
				o += [str(i + 1)]
				r = 0
				break
			else:
				b += [i + 1]
				s += 1
	if r == 1:
		for j in range(s, -1, -1):
			if b[j] <= v:
				o += [str(u // b[j])]
				break
print('\n'.join(o))


primes = set([2])
isPrime = [True for _ in range(4 * 10 ** 4)]
for i in range(3, len(isPrime), 2):
	if not isPrime[i]:
		continue
	primes.add(i)
	mul = 3
	while mul * i < len(isPrime):
		isPrime[mul * i] = False
		mul += 2
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k < 1000:
		for x in range(k, 0, -1):
			if n % x == 0:
				print(n // x)
				break
		continue
	x = n
	factors = []
	for p in primes:
		while x % p == 0:
			factors.append(p)
			x //= p
	factors.append(x)
	minBoxesNeeded = (n + k - 1) // k
	s = set([1])
	for f in factors:
		newStuff = set()
		for elem in s:
			newStuff.add(elem * f)
		for elem in newStuff:
			s.add(elem)
	ans = n
	for elem in sorted(list(s)):
		if elem > k:
			break
		ans = n // elem
	print(ans)


def fun(inp):
	result = [1]
	i = 1
	while i * i <= inp[0]:
		if inp[0] % i == 0:
			result.append(i)
			if inp[0] / i != i:
				result.append(inp[0] // i)
		i += 1
	result.sort(reverse=True)
	for i in range(len(result) + 1):
		if result[i] <= inp[1]:
			print(inp[0] // result[i])
			return
test_cases = int(input())
for i in range(test_cases):
	inp = input().split()
	for j in range(len(inp)):
		inp[j] = int(inp[j])
	fun(inp)


T = int(input())
II = 0
from math import *

def mindivisor(n):
	i = 1
	s = []
	while i <= sqrt(n):
		if n % i == 0:
			s.append(i)
		i += 1
	q = [d for d in s]
	for x in q:
		s.append(n // x)
	i = 0
	while i < len(s):
		if s[i] > k:
			s[i] = 0
		i += 1
	return n // max(s)
while II < T:
	s = input().split()
	n = int(s[0])
	k = int(s[1])
	if n <= k:
		print(1)
	elif k == 1:
		print(n)
	else:
		print(mindivisor(n))
	II += 1


def main():
	for t in range(int(input())):
		(n, k) = map(int, input().split())
		r = 1
		minPack = 10 ** 9 + 1
		while r * r <= n:
			if n % r == 0:
				if r <= k:
					minPack = min(minPack, n // r)
				if n // r <= k:
					minPack = min(minPack, r)
			r += 1
		print(minPack)
main()


import sys
import math
import collections

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

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

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

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 printDivisors(n):
	ans = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				ans.append(i)
			else:
				ans.append(i)
				ans.append(n // i)
		i = i + 1
	return ans
for t in range(int(input())):
	(n, k) = get_ints()
	if n <= k:
		print(1)
		continue
	elif k == 1:
		print(n)
		continue
	elif isPrime(n):
		print(n)
		continue
	else:
		factors = printDivisors(n)
		factors.sort()
		for i in factors:
			div = n // i
			if div <= k:
				print(i)
				break


def rs():
	return input().strip()

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

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

def ia_to_s(a):
	return ' '.join([str(s) for s in a])

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res
import math
primes = prime_list(int(math.sqrt(10 ** 9)) + 1)

def factorize(n):
	global primes
	i = 0
	d = {}
	while n > 1 and i < len(primes) and (primes[i] * primes[i] <= n):
		if n % primes[i] == 0:
			d[primes[i]] = 0
			while n % primes[i] == 0:
				d[primes[i]] += 1
				n //= primes[i]
		i += 1
	if n > 1:
		d[n] = 1
	return d
from functools import reduce

def divisors(n):
	factors = [(x[0], x[1]) for x in factorize(n).items()]
	nfactors = len(factors)
	f = [0] * nfactors
	while True:
		yield reduce(lambda x, y: x * y, [factors[x][0] ** f[x] for x in range(nfactors)], 1)
		i = 0
		while True:
			f[i] += 1
			if f[i] <= factors[i][1]:
				break
			f[i] = 0
			i += 1
			if i >= nfactors:
				return

def solve(n, k):
	if k >= n:
		return 1
	divs = sorted(list(divisors(n)), reverse=True)
	for d in range(len(divs)):
		if divs[d] <= k:
			return n // divs[d]
	return n

def main():
	for _ in range(ri()):
		(n, k) = ria()
		print(solve(n, k))
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	fact = []
	for i in range(1, int(pow(n, 0.5)) + 1):
		if n % i == 0:
			fact.append(i)
			fact.append(n // i)
	fact.sort()
	for i in range(len(fact) - 1, -1, -1):
		if fact[i] <= k:
			print(n // fact[i])
			break


import math
t = int(input())
for q in range(t):
	(n, k) = map(int, input().split())
	if k == 1:
		print(n)
		continue
	if k >= n:
		print(1)
		continue
	res = n
	for j in range(2, min(k + 1, int(math.sqrt(n)) + 1)):
		if n % j == 0 and n / j <= k:
			res = min(res, j)
		elif n % j == 0:
			res = min(res, n // j)
	print(res)


import math
for t in range(int(input())):
	(n, k) = map(int, input().split())
	ansDiv = 1
	upp = min(k, int(n ** 0.5) + 1)
	maxi = -1
	for i in range(1, upp + 1):
		if n % i == 0:
			maxi = max(maxi, i)
			if int(n / i) <= k:
				maxi = max(maxi, int(n / i))
	print(n // maxi)


import sys
import math
import collections
import threading

def main():
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
		return
	if n % k == 0:
		print(n // k)
		return
	lim = 1 + int(math.sqrt(n))
	ans = n
	for i in range(2, lim):
		if n % i == 0:
			if i <= k:
				ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
				break
	print(ans)
input = sys.stdin.readline
tn = int(input())
for _ in range(tn):
	main()


import math
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		factors = [1]
		for i in range(2, round(math.sqrt(n) + 1)):
			if n % i == 0:
				factors.append(i)
				if n // i != i:
					factors.append(n // i)
		factors.sort(reverse=True)
		for e in factors:
			if e <= k:
				print(n // e)
				break


T = int(input())

def md(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(reverse=True)
	return divisors
for _ in range(T):
	(n, k) = map(int, input().split())
	yaku = md(n)
	for i in yaku:
		if i <= k:
			print(n // i)
			break


r = int(input())
for t in range(0, r):
	(n, k) = map(int, input().split())
	x = 9999999999
	i = 1
	while i * i <= n:
		if n % i == 0:
			if i <= k:
				x = min(x, n // i)
			if n // i <= k:
				x = min(x, i)
		i += 1
	print(x)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		print(n)
		continue
	if k >= n:
		print('1')
		continue
	ans = []
	for x in range(1, int(math.sqrt(n)) + 1):
		if n % x == 0:
			q = n // x
			ans.append(x)
			ans.append(q)
	ans.sort()
	for j in range(len(ans) - 1, -1, -1):
		if ans[j] <= k:
			print(n // ans[j])
			break


def solve(n, k):
	ans = n
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i <= k:
				ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
	return ans
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	print(solve(n, k))


import math

def factor(n, k):
	lis = []
	i = 1
	b = math.sqrt(n)
	while i <= b:
		if n % i == 0:
			if i == b:
				lis.append(i)
			else:
				lis.append(i)
				lis.append(n // i)
		i += 1
	ans = 0
	for j in lis:
		if j <= k:
			ans = max(ans, j)
	return n // ans
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	print(factor(n, k))


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	p = 1
	r = n ** 0.5
	while p <= r:
		if n % p == 0:
			if p <= k:
				m = p
			if n // p <= k:
				m = n // p
				break
		p += 1
	print(n // m)


import math
t = int(input())

def check_prime(x):
	for i in range(2, int(math.sqrt(x)) + 1):
		if x % i == 0:
			return 0
	return 1
while t:
	(n, k) = map(int, input().split())
	check = 1
	if n <= k:
		print(1)
		t = t - 1
		continue
	if check_prime(n):
		print(n)
		t = t - 1
		continue
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			temp = n / i
			if temp <= k:
				print(i)
				check = 0
				break
	if check:
		for i in range(int(math.sqrt(n)), 1, -1):
			if n % i == 0:
				if i <= k:
					print(int(n / i))
					break
		else:
			print(n)
	t = t - 1


from sys import stdin, stdout
import bisect
import math

def st():
	return list(stdin.readline().strip())

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

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

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

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
		a *= a
		n = n >> 1
	return r

def solve():
	(n, k) = mp()
	l = []
	if n == k:
		print(1)
		return
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i != n // i:
				if i <= k:
					l.append(i)
				if n // i <= k:
					l.append(n // i)
			elif i <= k:
				l.append(i)
	l.sort()
	print(n // l[-1])
for _ in range(inp()):
	solve()


import math

def printDivisors(n):
	i = 1
	x = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				x.append(i)
			else:
				x += [i, n // i]
		i = i + 1
	return x
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	p = printDivisors(n)
	p = sorted(p, reverse=True)
	for item in p:
		if item <= k:
			print(n // item)
			break


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		mini = n
		for i in range(1, int(n ** (1 / 2)) + 1):
			if n % i == 0:
				e = int(n / i)
				if i <= k:
					mini = min(mini, e)
				if e <= k:
					mini = min(mini, i)
		print(mini)


from math import floor
for _ in [0] * int(input()):
	(n, k) = map(int, input().split())
	ans = 1
	for x in range(1, floor(n ** 0.5) + 1):
		if n % x == 0:
			ans = max(ans, x * int(x <= k), n // x * int(n // x <= k))
	print(n // ans)


for i in ' ' * int(input()):
	(a, b) = map(int, input().split())
	c = []
	s = 1
	while s * s <= a:
		if a % s == 0:
			c.append(s)
			if s != a // s:
				c.append(a // s)
		s += 1
	c.sort(reverse=True)
	for j in c:
		if j <= b:
			print(a // j)
			break


import math
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	if k == 1:
		print(n)
		continue
	if k >= n:
		print(1)
		continue
	l = list()
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			l.append(i)
			l.append(n / i)
	l.sort()
	for i in range(len(l)):
		if l[i] > k:
			print(int(n // l[i - 1]))
			break


from math import sqrt
for T in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if n <= k:
		print(1)
	elif k == 1:
		print(n)
	else:
		temp = 1
		mn = 1000000000.0
		if n % 2 == 0:
			mn = min(mn, n // 2)
			if n // 2 <= k:
				temp = 0
				print(2)
		if temp == 1:
			res = -1
			ind = min(int(sqrt(n)), k)
			for i in range(3, ind + 1):
				if n % i == 0:
					mn = min(mn, n // i)
					if n // i <= k:
						mn = min(mn, i)
			if mn == 1000000000.0:
				print(n)
			else:
				print(mn)


T = int(input())
for _ in range(T):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if k >= n:
		print('1')
	else:
		flag = 0
		ans = 1
		for i in range(2, min(k + 1, int(n ** 0.5) + 1)):
			if n % i == 0:
				ans = i
				if int(n / i) != i and int(n / i) <= k:
					ans = int(n / i)
					flag = 1
					break
		print(int(n / ans))


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 ** 19
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()
	divs = sorted(divisors(N))
	for div in divs[::-1]:
		if div <= K:
			print(N // div)
			break


import sys
from math import ceil, sqrt, sin, pi, tan
from collections import defaultdict
read = sys.stdin.buffer.readline
import heapq
mi = lambda : map(int, read().split())
li = lambda : list(mi())
cin = lambda : int(read())

def isp(n):
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	return True
ps = lambda x: x == pow(int(sqrt(x)), 2)
for _t in range(cin()):
	(n, k) = mi()
	mx = 1
	i = 1
	while i * i <= n:
		if n % i == 0:
			if i <= k:
				mx = max(i, mx)
			if n // i != i and n // i <= k:
				mx = max(n // i, mx)
		i += 1
	print(n // mx)


from sys import stdin
from functools import reduce

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

def func(arr, start, end, val):
	while end - start > 1:
		mid = (start + end) // 2
		if arr[mid] > val:
			end = mid - 1
		else:
			start = mid
	if arr[end] <= val:
		return arr[end]
	else:
		return arr[start]
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		ans = factors(n)
		ans = sorted(list(filter(lambda x: x <= k, ans)))
		print(n // ans[-1])


import math

def printDivisors(n, result):
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				if i > result and i <= K:
					result = i
			else:
				if i > result and i <= K:
					result = i
				if n // i > result and n // i <= K:
					result = n // i
		i = i + 1
	return result
for _ in range(int(input())):
	(N, K) = list(map(int, input().split()))
	if K >= N:
		print(1)
	elif K == 1:
		print(N)
	else:
		result = 1
		print(N // printDivisors(N, result))


import math

def func(n, k):
	i = 1
	ans = float('inf')
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				if k >= i:
					ans = min(ans, n // i)
			elif k >= i and k >= n // i:
				ans = min(ans, i, n // i)
			elif k >= i:
				ans = min(ans, n // i)
			elif k >= n // i:
				ans = min(ans, i)
		i = i + 1
	return ans
t = int(input())
while t:
	(n, k) = map(int, input().rstrip().split())
	print(func(n, k))
	t -= 1


import bisect

def factors(x):
	result = []
	i = 1
	while i * i <= x:
		if x % i == 0:
			result.append(i)
			if x // i != i:
				result.append(x // i)
		i += 1
	return result
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	cnt = 1
	factor = factors(n)
	factor.sort()
	factor = factor[::-1]
	for i in factor:
		if i <= k:
			print(n // i)
			break


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	div = [1]
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			div.append(i)
			div.append(n // i)
	div.append(n)
	div = sorted(div, reverse=True)
	for i in div:
		if i <= k:
			print(n // i)
			break


from math import sqrt
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		m = 0
		flag = 0
		for i in range(1, min(int(sqrt(n)), k) + 1):
			if n % i == 0:
				if n // i <= k:
					print(i)
					flag = 0
					break
				elif m == 0 or m > n // i:
					m = n // i
					flag = 1
		if flag:
			print(m)


import math

def solve(n, k):
	if k >= n:
		return 1
	min_packages = n
	for i in range(2, min(k, math.ceil(n ** 0.5)) + 1):
		if n % i == 0:
			div1 = n // i
			if div1 <= k:
				min_packages = min(min_packages, i)
			min_packages = min(min_packages, div1)
	return min_packages

def main():
	t = int(input())
	for i in range(t):
		d = input()
		d = [int(i) for i in d.split()]
		n = d[0]
		a = d[1]
		ans = solve(n, a)
		print(ans)
main()


import sys
import math

def solve():
	return None

def main():
	q = []
	for line in sys.stdin.readlines():
		q.append(line)
	for i in range(len(q)):
		q[i] = q[i].rstrip().split(' ')
		q[i] = [int(x) for x in q[i]]
	for i in range(1, len(q)):
		n = q[i][0]
		k = q[i][1]
		sol = 0
		inverted = 0
		if k == 1:
			sol = n
		elif k >= n:
			sol = 1
		else:
			i = 1
			while i * i <= n:
				if n % i == 0:
					if i <= k:
						inverted = n / i
					if n / i <= k:
						sol = i
						break
				i += 1
			if sol == 0:
				sol = inverted
		print(int(sol))
main()


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		t = []
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0 and i <= k:
				t.append(i)
				t.append(n // i)
		t.sort()
		if t == []:
			print(n)
		else:
			for j in range(len(t)):
				if n // t[j] <= k:
					print(t[j])
					break


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	q = 0
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i <= k and n // i <= k:
				q = max(q, i, n // i)
			elif i <= k and n // i > k:
				q = max(q, i)
	print(n // q)


from math import sqrt
from bisect import bisect_left
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a <= b:
		print(1)
	elif a % b == 0:
		print(a // b)
	else:
		f = []
		for i in range(2, int(sqrt(a)) + 1):
			if a % i == 0:
				f.append(i)
				f.append(a // i)
		f = list(set(f))
		f.sort()
		kl = bisect_left(f, b)
		if kl == 0:
			print(a)
		else:
			print(a // f[kl - 1])


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi
import heapq

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.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 printDivisors(n):
	i = 1
	ans = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				ans.append(i)
			else:
				ans.append(i)
				ans.append(n // i)
		i = i + 1
	return ans

def main():
	try:
		(n, k) = In()
		z = printDivisors(n)
		ma = 0
		for x in z:
			if x <= k:
				if x > ma:
					ma = x
		print(n // ma)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


import math

def solve(n, k):
	if k >= n:
		print(1)
		return
	tmp = n
	cur = 2
	arr = [1]
	while cur <= math.sqrt(n):
		if tmp % cur == 0:
			arr.append(cur)
		cur += 1
	res = 1
	for val in arr:
		if val <= k:
			res = max(val, res)
		if n // val <= k:
			res = max(n // val, res)
	print(n // res)
	return
t = int(input())
for i in range(0, t):
	(n, k) = map(int, input().split())
	solve(n, k)


import math

def primenum(x):
	count = 0
	for i in range(2, int(math.floor(math.sqrt(x))) + 1):
		if x % i == 0:
			count = count + 1
	if count == 0:
		return True
	else:
		return False
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif primenum(n) == True:
		print(n)
	else:
		y = n
		for j in range(1, int(math.sqrt(n)) + 1):
			if n % j == 0:
				if j <= k:
					y = min(y, n // j)
				if n // j <= k:
					y = min(y, j)
		print(y)


import math
for _ in range(int(input())):
	(n, a) = map(int, input().split())
	m = n
	if n <= a:
		print(1)
	else:
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				if i <= a:
					m = min(m, n // i)
				if n // i <= a:
					m = min(m, i)
		print(m)


T = int(input())
import math
for t in range(T):
	(n, k) = map(int, input().split())
	res = 0
	for i in range(min(int(math.sqrt(n)), k), 0, -1):
		if n % i == 0:
			if i > res:
				res = i
			if n // i > res and n // i <= k:
				res = n // i
	print(n // res)


import math
for _ in range(int(input())):
	(shovels, packages) = map(int, input().split(' '))
	lowest = 10 ** 18
	for i in range(1, int(math.sqrt(shovels)) + 1):
		if shovels % i == 0:
			if shovels // i <= packages:
				lowest = min(lowest, i)
			if i <= packages:
				lowest = min(lowest, shovels // i)
	print(lowest)


import sys
input = lambda : sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline

def I():
	return list(map(int, inp().split()))
from math import sqrt, inf
for _ in range(I()[0]):
	(n, k) = I()
	ans = inf
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if n // i <= k:
				ans = min(i, ans)
			if i <= k:
				ans = min(n // i, ans)
	print(ans)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	m = 0
	for i in range(1, min(k, int(n ** 0.5)) + 1):
		if n % i == 0:
			if n // i <= k:
				m = n // i
				break
			m = i
	print(n // m)


t = int(input())

def solve(n, k):
	if k >= n:
		return 1
	factors = []
	for d in range(1, int(n ** 0.5) + 1):
		if n % d == 0:
			factors.append(d)
			factors.append(n // d)
	factors.sort(reverse=True)
	for d in factors:
		if d <= k:
			return n // d
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	print(solve(n, k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	i = 2
	c = []
	s = int(n ** 0.5) + 1
	while i <= k and i < s:
		if n % i == 0:
			c.append(i)
			if n // i <= k:
				c.append(n // i)
		i += 1
	if k >= n:
		print(1)
	elif n % k == 0:
		print(n // k)
	elif len(c) > 0:
		print(n // max(c))
	else:
		print(n)


from sys import stdin, stdout
input = lambda : stdin.readline().strip()
fast_print = stdout.write
from math import sqrt, floor
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	res = []
	for i in range(floor(sqrt(n)), 0, -1):
		if n % i == 0:
			if 1 <= n // i <= k:
				res.append(i)
			if 1 <= i <= k:
				res.append(n // i)
	print(min(res))


import math
import random
mod = 1000000007
r1 = lambda : int(input())
rm = lambda : map(int, input().split())
rls = lambda : list(rm())
test = r1()
while test:
	test -= 1
	(n, k) = rm()
	if n <= k:
		print(1)
	else:
		ans = 1
		x = int(n ** 0.5) + 1
		ls = []
		while x >= 1:
			if n % x == 0:
				if n // x == x:
					ls.append(x)
				else:
					ls.append(x)
					ls.append(n // x)
			x -= 1
		ans = 0
		ls.sort()
		for i in ls[::-1]:
			if i <= k:
				print(n // i)
				break


import math
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	ans = 0
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i <= k:
				ans = max(ans, i)
			if n / i <= k:
				ans = max(ans, n / i)
	print(int(n / ans))


from sys import stdin, stdout, maxsize
import math
t = int(stdin.readline())
for _ in range(t):
	(a, b) = map(int, stdin.readline().split())
	m = 0
	z = int(math.sqrt(a))
	for i in range(1, z + 1):
		if a % i == 0:
			k = a // i
			if i >= m and i <= b:
				m = i
			if k >= m and k <= b:
				m = k
	ans = a // m
	stdout.write(str(ans) + '\n')


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = n
	if k >= n:
		print(1)
	else:
		for i in range(1, int(math.sqrt(n)) + 1):
			if n % i == 0:
				f1 = n / i
				f2 = i
				if n // f1 <= k:
					ans = min(ans, f1)
				if n // f2 <= k:
					ans = min(ans, f2)
		print(int(ans))


def main():
	(n, k) = map(int, input().split())
	ans = 10000000000.0
	if n <= k:
		print('1')
	elif n % k == 0:
		print(n // k)
	else:
		i = 1
		while i * i <= n:
			if n % i == 0:
				if i <= k:
					ans = min(n // i, ans)
				if n // i <= k:
					ans = min(i, ans)
			i += 1
		print(ans)
	return

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


import os
import sys
from io import BytesIO, IOBase

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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()
import math
for _ in range(int(input())):
	(shovels, packages) = map(int, input().split(' '))
	lowest = 10 ** 18
	for i in range(1, int(math.sqrt(shovels)) + 1):
		if shovels % i == 0:
			if shovels // i <= packages:
				lowest = min(lowest, i)
			if i <= packages:
				lowest = min(lowest, shovels // i)
	print(lowest)


import math
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	ans = n
	facarr = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				facarr.append(i)
			else:
				if n // i <= k:
					ans = i
					break
				facarr.append(i)
		i = i + 1
	if ans == n:
		l = len(facarr)
		i = l - 1
		while i >= 0:
			if facarr[i] <= k:
				ans = n // facarr[i]
				break
			i -= 1
	print(ans)


import math

def printDivisors(n):
	i = 1
	l1 = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				l1.append(i)
			else:
				l1.append(i)
				l1.append(n // i)
		i = i + 1
	return l1
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l1 = printDivisors(n)
	l1.sort(reverse=True)
	for j in range(len(l1)):
		if l1[j] <= k:
			print(n // l1[j])
			break


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	f = 1
	for i in range(1, min(int(n ** 0.5), k) + 1):
		if n % i == 0:
			if n // i <= k:
				f = max(f, n // i, i)
			else:
				f = max(f, i)
	print(n // f)


def fact(n):
	factors = []
	for j in range(1, int(n ** 0.5) + 1):
		if n % j == 0:
			factors.append(j)
			factors.append(int(n / j))
	factors.sort()
	return factors
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	aa = fact(n)
	for j in range(len(aa)):
		if n / aa[j] <= k:
			print(aa[j])
			break


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

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

def fi():
	return float(stdin.readline())

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

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

def li():
	return list(mi())

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline().rstrip()
res = ['YES', 'NO']

def sieve(x):
	a = [True] * (x + 1)
	sq = floor(sqrt(x))
	for i in range(3, sq + 1, 2):
		if a[i]:
			for j in range(i * i, x + 1, i):
				a[j] = False
	if x > 1:
		p = [2]
	else:
		p = []
	for i in range(3, x + 1, 2):
		if a[i]:
			p.append(i)
	return p
test_case = ii()
while test_case:
	test_case -= 1
	(n, k) = mi()
	if k >= n:
		print(1)
		continue
	ans = n
	for i in range(2, min(k + 1, int(sqrt(n)) + 1)):
		if not n % i:
			ans = n // i
			if n // i <= k:
				ans = i
				break
	print(ans)


def factors(n):
	i = 1
	b = []
	p = int(n ** 0.5)
	while i <= p:
		if n % i == 0:
			if n // i == i:
				b.append(i)
			else:
				b.append(i)
				b.append(n // i)
		i = i + 1
	return b
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	b = factors(n)
	b.sort()
	b.reverse()
	for i in b:
		if i <= k:
			print(n // i)
			break


import sys
import math
from collections import defaultdict as dd
mod = 1000000007
T = 1
T = int(sys.stdin.readline())
for _ in range(T):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		sq = int(math.sqrt(n))
		p = min(k, sq)
		ans = n
		for i in range(p, 0, -1):
			if n % i == 0:
				q = n // i
				if k >= q:
					ans = min(ans, i)
				ans = min(ans, q)
		print(ans)


import sys
f_in = sys.stdin
f_out = sys.stdout
i = int(f_in.readline())
for _ in range(i):
	pair = f_in.readline().split(' ')
	pair = [int(x) for x in pair]
	n = pair[0]
	k = pair[1]
	answer = n
	s = 1
	if k >= n:
		answer = 1
	else:
		while s * s <= n and s <= k:
			if n % s == 0:
				answer = min(n / s, answer)
				if n / s <= k:
					answer = min(s, answer)
			s += 1
	f_out.write(str(int(answer)) + '\n')


import sys
import math as m

def fi():
	return sys.stdin.readline()
for _ in range(int(fi())):
	(n, k) = map(int, input().split())
	min1 = sys.maxsize
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0 and (i <= k or n // i <= k):
			if n // i <= k:
				min1 = min(min1, i)
			else:
				min1 = min(min1, n // i)
	print(min1)


from sys import stdin
import math
from functools import reduce
from math import sqrt

def factors(n):
	step = 2 if n % 2 else 1
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(sqrt(n)) + 1, step) if n % i == 0)))
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, k) = [int(x) for x in inp().split()]
	if n <= k:
		print(1)
	else:
		f = factors(n)
		f = sorted(f)
		maxi = min(f)
		for i in f:
			if i > k:
				break
			maxi = max(maxi, i)
		print(n // maxi)


cases = int(input())
for t in range(cases):
	(n, k) = list(map(int, input().split()))
	if n <= k:
		print(1)
	else:
		f = 1
		v = min(k, int(n ** 0.5))
		for i in range(1, v + 1):
			if n % i == 0:
				f = max(f, i)
				if n // i <= k:
					f = max(f, n // i)
		print(n // f)


import math
t = int(input())

def pd(n):
	list = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				list.append(i)
			else:
				list.append(i)
				list.append(int(n // i))
	return list
for _ in range(t):
	(n, k) = map(int, input().split())
	z = 1
	ans = 1
	l = pd(n)
	l.sort(reverse=True)
	ans = 0
	for i in l:
		if i <= k:
			print(n // i)
			break


import math
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if b >= a:
		print(1)
		continue
	if b == 1:
		print(a)
		continue
	x = 0
	y = 0
	maxi = 0
	c = int(math.sqrt(a))
	for j in range(1, c + 1):
		if a % j == 0 and j <= b:
			x = j
			y = a // x
			if max(x, y) >= maxi and max(x, y) <= b:
				maxi = max(x, y)
			elif min(x, y) >= maxi and min(x, y) <= b:
				maxi = min(x, y)
	print(a // maxi)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	if n <= k:
		print(1)
	else:
		ok = False
		divmax = -1
		for i in range(1, int(n ** 0.5) + 2):
			if i > k:
				break
			if n % i == 0 and int(n / i) <= k:
				divmax = max(i, n / i, divmax)
			if n % i == 0 and int(n / i) > k:
				divmax = max(divmax, i)
		print(int(n / divmax))


import math
tc = int(input())
for _ in range(tc):
	(a, b) = list(map(int, input().split(' ')))
	found = 1
	for fac in range(1, int(math.sqrt(a)) + 1):
		if a % fac == 0:
			if fac <= b:
				found = max(fac, found)
			if a // fac <= b:
				found = max(found, a // fac)
	if found is not None:
		print(a // found)
	else:
		print(a)


from sys import stdin, stdout
for query in range(int(stdin.readline())):
	nk = stdin.readline().split()
	n = int(nk[0])
	k = int(nk[1])
	lowest = 10000000000
	mybool = False
	count = 0
	for x in range(1, int(n ** 0.5) + 1):
		count += 1
		if n % x == 0:
			if n // x <= k:
				stdout.write(str(x) + '\n')
				mybool = True
				break
			if x <= k:
				lowest = n // x
	if mybool:
		continue
	stdout.write(str(lowest) + '\n')


testcase = int(input())
for i in range(testcase):
	(n, m) = map(int, input().split())
	li2 = []
	for p in range(1, int(n ** (1 / 2)) + 1):
		if n % p == 0:
			if n / p == p:
				num = p
				if num <= m:
					li2.append(num)
			else:
				num = p
				num2 = n // p
				if num2 <= m:
					li2.append(num2)
				if num <= m:
					li2.append(num)
	print(int(n / max(li2)))


from math import sqrt
t = int(input())
for j in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print('1')
	else:
		ans = 1
		l = int(sqrt(n)) + 1
		for i in range(1, l, 1):
			if n % i == 0:
				if i <= k:
					ans = max(ans, i)
				if i != sqrt(n):
					if n / i <= k:
						ans = max(ans, n / i)
		print(int(n / ans))


import math
t = int(input())
while t != 0:
	(n, k) = map(int, input().split())
	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 += 1
	B = sorted(A)
	tmp = 0
	for x in range(len(B)):
		if B[x] > k:
			print(int(n / B[x - 1]))
			tmp = 1
			break
	if tmp == 0:
		print(1)
	t -= 1


import math
t = int(input())
for z in range(t):
	(n, m) = list(map(int, input().split()))
	if m >= n:
		print(1)
	else:
		num = int(min(math.sqrt(n), m))
		ans = n
		for i in range(1, num + 1):
			if n % i == 0:
				(n1, n2) = (n // i, i)
				if n2 <= m:
					ans = min(ans, n1)
				if n1 <= m:
					ans = min(ans, n2)
		print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
		continue
	ans = n
	for i in range(min(k, int(n ** 0.5)), 0, -1):
		if n % i == 0:
			ans = min(ans, n // i)
			if n // i <= k:
				ans = i
	print(ans)


from math import sqrt
from collections import defaultdict as dd, deque
import sys
input = sys.stdin.readline
t = int(input())
while t:
	(n, k) = map(int, input().split())
	mx = 1
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if i <= k:
				mx = max(mx, i)
			if n // i <= k:
				mx = max(mx, n // i)
	print(n // mx)
	t -= 1


import os, sys
from math import *
t = int(input())
for nc in range(t):
	(n, k) = [int(x) for x in input().strip().split()]
	if k >= n:
		print(1)
	else:
		ans = n
		lim = min(k, floor(sqrt(n)))
		for i in range(lim, 1, -1):
			if n % i == 0:
				if n // i <= k:
					ans = i
				else:
					ans = min(ans, n // i)
		print(ans)


n = int(input())
inputList = []
for i in range(n):
	inputList.append(list(map(int, input().split(' ')))[:2])

def getFactors(x):
	results = []
	i = 1
	while i * i <= x:
		if x % i == 0:
			results.append(i)
			if x // i != i:
				results.append(x // i)
		i += 1
	return results

def min_package(n, k):
	if k >= n:
		return 1
	factors = getFactors(n)
	factors.sort(reverse=True)
	for i in factors:
		if i <= k:
			return n // i
for i in range(n):
	print(min_package(inputList[i][0], inputList[i][1]))


t = int(input())
arr = []
for i in range(t):
	c = list(map(int, input().split(' ')))
	arr.append(c.copy())
for i in arr:
	(n, k) = (i[0], i[1])
	ans = n
	i = 1
	while i * i <= n and i <= k:
		if n % i == 0:
			if n // i <= k:
				ans = i
				break
			ans = min(ans, n // i)
		i += 1
	print(ans)


from collections import Counter
t = int(input())
while t > 0:
	t = t - 1
	(n, k) = map(int, input().split())
	f = []
	ans = []
	if k >= n:
		print(1)
	else:
		for i in range(1, min(k + 1, int(n ** 0.5) + 1)):
			if n % i == 0:
				f.append(i)
		for i in f:
			ans.append(n // i)
			if n // i <= k:
				ans.append(i)
		print(min(ans))


from sys import stdin
import math
inp = lambda : stdin.readline().strip()

def Divisors(n, k):
	divisors = []
	i = 1
	minimum = min(math.sqrt(n), k)
	while i <= minimum:
		if n % i == 0:
			if n // i == i:
				divisors.append(i)
			else:
				divisors.append(i)
				if n // i <= k:
					divisors.append(n // i)
		i = i + 1
	return divisors
t = int(inp())
for _ in range(t):
	(n, k) = [int(x) for x in inp().split()]
	print(n // max(Divisors(n, k)))


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	ar = []
	i = 1
	while i * i <= n:
		if n % i == 0:
			ar.append(i)
			ar.append(n // i)
		i += 1
	ar.sort()
	i = len(ar) - 1
	ans = n
	while i >= 0:
		if ar[i] <= k:
			ans = n // ar[i]
			break
		i -= 1
	print(ans)


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

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

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


import sys
import math
t = int(input())
while t:
	(n, k) = map(int, sys.stdin.readline().split())
	if k == 1:
		print(n)
	elif n <= k:
		print(1)
	else:
		flag = 0
		i = 2
		ans = n
		while i * i <= n:
			if n % i == 0:
				if n // i <= k:
					ans = min(ans, i)
				if i <= k:
					ans = min(ans, n // i)
			i += 1
		print(ans)
	t -= 1


import math as m
t = int(input())
for i in range(t):
	mx = 0
	(n, k) = map(int, input().split())
	i = 1
	while i * i <= n:
		if n % i == 0:
			div = n // i
			if i <= k:
				mx = max(mx, i)
			if div <= k:
				mx = max(mx, div)
		i += 1
	print(n // mx)


from fractions import Fraction
import sys
import bisect
import heapq
from math import *
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
mod = pow(10, 9) + 7

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

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 graph(vertex):
	return [[] for i in range(0, vertex + 1)]

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 is_prime(n):
	if n == 1:
		return False
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def solve():
	(n, k) = sep()
	if k >= n:
		print(1)
	else:
		ans = 1
		for i in range(2, min(floor(n ** 0.5) + 1, k + 1)):
			if n % i == 0:
				ans = max(ans, i)
				if n // i <= k:
					ans = max(ans, n // i)
		print(n // ans)
testcase(int(inp()))


from math import sqrt, ceil
from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def divisors(n):
	result = set([1])
	for i in range(2, ceil(sqrt(n)) + 1):
		if n % i == 0:
			result.add(i)
			result.add(n // i)
	return sorted(list(result))

def solve(n, k):
	if k >= n:
		return 1
	for item in divisors(n):
		if n // item <= k:
			return item
	return n
for i in tests():
	(n, k) = arr_in()
	out(solve(n, k))


def div(n, k):
	ans = 1
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			ch1 = i
			ch2 = n // i
			if ch1 <= k and ch1 > ans:
				ans = ch1
			if ch2 <= k and ch2 > ans:
				ans = ch2
	return ans
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		ans = 1
	else:
		ch = div(n, k)
		ans = n // ch
	print(ans)


import math
t = int(input())

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 printDivisors(n, k, ans):
	i = 1
	while i <= math.sqrt(n) and i <= k:
		if n % i == 0:
			ans.append(i)
			if n // i <= k:
				ans.append(n // i)
		i = i + 1
while t != 0:
	ans = []
	t -= 1
	(n, k) = [int(x) for x in input().split()]
	if isPrime(n):
		if n <= k:
			print(1)
		else:
			print(n)
	elif n <= k:
		print(1)
	else:
		printDivisors(n, k, ans)
		ans.sort()
		print(n // ans[-1])


import sys
import math
from collections import Counter
from collections import OrderedDict
from functools import reduce
sys.setrecursionlimit(10 ** 6)

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

def printt(n):
	sys.stdout.write(str(n) + '\n')

def listt():
	return [int(i) for i in inputt().split()]

def gcd(a, b):
	return math.gcd(a, b)

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

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)))

def comb(n, k):
	factn = math.factorial(n)
	factk = math.factorial(k)
	fact = math.factorial(n - k)
	ans = factn // (factk * fact)
	return ans
t = int(inputt())
for _ in range(t):
	(n, k) = map(int, inputt().split())
	if n <= k:
		printt(1)
	else:
		g = math.sqrt(n)
		se = list(factors(n))
		se.sort(reverse=True)
		for i in se:
			if i <= k:
				printt(n // i)
				break


for nt in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	ans = n
	for i in range(1, min(int(n ** 0.5) + 1, k + 1)):
		if n % i == 0:
			ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
	print(ans)


t = int(input())
for i in range(t):
	r = 0
	(n, k) = map(int, input().split())
	for i in range(1, int(n ** 0.5 + 1)):
		if i > k:
			break
		elif n % i == 0:
			r = n // i
			if k >= r:
				r = i
				break
	print(r)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if a % b == 0:
		print(a // b)
	elif b >= a:
		print(1)
	else:
		f = 0
		for k in range(1, int(a ** 0.5) + 1):
			if a % k == 0 and a // k <= b:
				print(k)
				f = 1
				break
		if f == 0:
			for k in range(int(a ** 0.5), 0, -1):
				if a % k == 0 and k <= b:
					print(a // k)
					f = 1
					break


import math
test_count = int(input())
for i in range(test_count):
	(n, k) = map(int, input().split())
	max_div = 1
	for i in range(int(math.sqrt(n)), 0, -1):
		if n % i == 0:
			if i <= k:
				if n // i <= k:
					if max_div < max(i, n // i):
						max_div = max(i, n // i)
				elif max_div < i:
					max_div = i
	print(n // max_div)


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from copy import deepcopy

def solution(n, k):
	i = 1
	min_ans = n
	while i * i <= n:
		if n % i == 0:
			if i <= k:
				min_ans = min(min_ans, n // i)
			if n // i <= k:
				min_ans = min(min_ans, i)
		i += 1
	return min_ans

def main():
	T = read_int()
	for i in range(T):
		(n, k) = read_int_array()
		x = solution(n, k)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


import sys
import os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
depth = 1000005
mod = 1000000007
sys.setrecursionlimit(depth)
from math import inf, sqrt
from collections import defaultdict
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if m >= n:
		print(1)
		continue
	ans = n
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			if i <= m:
				ans = min(ans, n // i)
			if n // i <= m:
				ans = min(ans, i)
	print(ans)


t = int(input())
import math
ll = []

def Divisors(n):
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				ll.append(i)
			else:
				ll.append(i)
				ll.append(n / i)
		i = i + 1
for i in range(t):
	(total, siz) = list(map(int, input().split()))
	if total <= siz:
		print(1)
		continue
	ans = total
	Divisors(total)
	ll.sort(reverse=True)
	for i in ll:
		if i <= siz:
			ans = total / i
			break
	ll = []
	print(int(ans))


import math
n = int(input())
for t in range(n):
	b = input().split()
	(n, k) = (int(b[0]), int(b[1]))
	if k >= n:
		print(1)
	else:
		res = n
		for i in range(1, int(math.sqrt(n)) + 1):
			if n % i == 0:
				if k >= i:
					res = min(res, n // i)
				if n // i <= k:
					res = min(res, i)
		print(res)


import math
for i1 in range(int(input())):
	(n, k) = map(int, input().split())
	root = int(math.sqrt(n))
	if k >= n:
		print(1)
		continue
	lim = min(k, root)
	flag = 0
	for i in range(2, lim + 1):
		if n % i == 0:
			flag = 1
			temp = n // i
			if temp <= k:
				temp = i
				break
	if flag:
		print(temp)
	else:
		print(n)


from sys import stdin
import math
a = int(stdin.readline())
for b in range(0, a):
	A = stdin.readline().split()
	N = int(A[0])
	K = int(A[1])
	MIN = N
	for l in range(1, int(math.floor(math.sqrt(N))) + 1):
		if N % l == 0:
			if int(l) <= K:
				MIN = min(MIN, int(N / l))
			if int(N / l) <= K:
				MIN = min(MIN, l)
	print(MIN)


import math

def findAllFactors(n):
	factors = []
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			factors.append(i)
			factors.append(n // i)
	return factors
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	fact = findAllFactors(n)
	fact.sort()
	j = -1
	for i in range(len(fact)):
		if fact[i] > k:
			j = i - 1
			break
	if j == -1:
		print(n // fact[-1])
	else:
		print(n // fact[j])


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	ans = a
	for i in range(1, min(int(pow(a, 0.5)) + 2, b + 1)):
		if a % i == 0:
			if i <= b:
				ans = min(ans, a // i)
			if a / i <= b:
				ans = min(ans, i)
	print(ans)


from sys import stdin, stdout
import math
t = int(input())
for i in range(t):
	(n, k) = list(map(int, stdin.readline().split()))
	ans = n
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i <= k:
				ans = min(ans, int(n / i))
			if n / i <= k:
				ans = min(ans, i)
	print(ans)


def read():
	return list(map(int, input().split()))
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)))
for t in range(int(input())):
	(n, k) = read()
	if n < k:
		print(1)
	else:
		ans = factors(n)
		for i in reversed(sorted(ans)):
			if i <= k:
				print(n // i)
				break


import math
T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	result = 0
	for d in range(1, int(math.sqrt(n)) + 1):
		if n % d == 0 and n // d <= k:
			result = d
			break
		elif n % d == 0 and d <= k:
			result = n // d
	print(result)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		factors = [f for f in range(2, int(n ** 0.5) + 1) if n % f == 0]
		factors += [n // f for f in reversed(factors)]
		for factor in reversed(factors):
			(q, r) = divmod(n, factor)
			if factor <= k and r == 0:
				print(q)
				break
		else:
			print(n)


from sys import stdin
from math import sqrt

def r():
	return stdin.readline().strip()

def r_t(tp):
	return map(tp, r().strip().split())

def r_a(tp):
	return list(r_t(tp))

def getDivisors(n):
	divs = list()
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			divs.append(i)
			if n // i != i:
				divs.append(n // i)
	return divs

def solve(n, k):
	if n <= k:
		return 1
	ans = n
	divs = getDivisors(n)
	divs.sort()
	for div in divs:
		if div > k:
			break
		ans = min(ans, n // div)
	return ans

def main():
	cases = int(r())
	for case in range(cases):
		(n, k) = r_t(int)
		print(solve(n, k))
main()


import math
import time

def is_prime(n):
	if n <= 1:
		return False
	if n == 2:
		return True
	if n > 2 and n % 2 == 0:
		return False
	max_div = math.floor(math.sqrt(n))
	for i in range(3, 1 + max_div, 2):
		if n % i == 0:
			return False
	return True
t = int(input())
for i in range(0, t):
	(n, k) = list(map(int, input().split()))
	if k >= n:
		print(1)
	elif n % k == 0:
		print(n // k)
	elif is_prime(n):
		print(n)
	else:
		p = 1
		l = []
		while p <= math.sqrt(n):
			if n % p == 0:
				if n / p == p:
					l.append(p)
				else:
					l.append(n // p)
					l.append(p)
			p += 1
		l.sort()
		for j in range(len(l) - 1, -1, -1):
			if l[j] <= k:
				print(n // l[j])
				break


import math

def divisorGenerator(n):
	large_divisors = []
	for i in range(2, 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

def is_prime(n):
	if n == 1:
		return False
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	return True
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a <= b:
		print(1)
	elif is_prime(a):
		print(a)
	else:
		ans = list(divisorGenerator(a))
		for j in ans:
			if a / j <= b:
				print(int(j))
				break
		else:
			print(a)


import math
T = int(input())
for _ in range(T):
	(n, k) = list(map(int, input().split()))
	ans = n
	for i in range(1, math.ceil(math.sqrt(n)) + 1):
		if n % i == 0:
			if i <= k:
				ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
	print(ans)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.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())
sys.setrecursionlimit(1500)

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_right(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(n, k) = In()
		if n <= k:
			print(1)
		else:
			mi = n
			for i in range(1, int(n ** 0.5) + 1):
				if n % i == 0:
					if i <= k:
						mi = min(n // i, mi)
					if n // i <= k:
						mi = min(mi, i)
			print(mi)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


from math import sqrt
for t in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		x = []
		for i in range(2, int(sqrt(n)) + 1):
			if n % i == 0:
				if n // i <= k:
					x.append(i)
					break
				elif i <= k:
					x.append(n // i)
		if x:
			print(x[-1])
		else:
			print(n)


import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__

def go():
	(n, k) = map(int, input().split())
	best = 1
	for i in range(1, min(int(n ** 0.5) + 1, k + 1)):
		(d, m) = divmod(n, i)
		if m == 0:
			if d <= k:
				return i
			else:
				best = d
	return best
t = int(input())
ans = []
for _ in range(t):
	ans.append(str(go()))
print('\n'.join(ans))


import sys
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)))

def process():
	(n, k) = [int(s) for s in sys.stdin.readline().split()]
	for f in sorted(list(factors(n)), reverse=True):
		if f <= k:
			print(n // f)
			return
T = int(sys.stdin.readline())
for x in range(T):
	process()


t = int(input())
import math

def factors(a, b):
	k = []
	for i in range(1, int(math.sqrt(a)) + 1):
		if i > b:
			break
		if a % i == 0:
			k.append(i)
			if a / i <= b:
				k.append(a / i)
	return k
for i in range(t):
	(a, b) = map(int, input().split())
	if b >= a:
		print(1)
	else:
		f = factors(a, b)
		f = sorted(f, reverse=True)
		for i in f:
			if a % i == 0:
				print(int(a // i))
				break


import math

def printDivisors(n):
	res = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				res.append(i)
			else:
				res.append(i)
				res.append(n // i)
		i = i + 1
	return res
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	x = printDivisors(n)
	x.sort()
	for i in range(len(x)):
		if x[i] > k:
			print(n // x[i - 1])
			break
		elif x[i] == k:
			print(n // x[i])
			break
		else:
			if i == len(x) - 1:
				print(n // x[i])
			pass


import math
T = int(input())
for t in range(T):
	(N, K) = list(map(int, input().split()))
	end = int(math.sqrt(N)) + 1
	res = 1
	if K < N:
		res = N
		for i in range(2, end):
			if N % i == 0:
				div2 = N // i
				div1 = i
				if div1 <= K:
					res = min(res, div2)
				if div2 <= K:
					res = min(res, div1)
	print(res)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	ans = 1
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		if i <= k and n % i == 0:
			ans = max(ans, i)
			if n // i <= k:
				ans = max(ans, n // i)
	print(n // ans)


from math import ceil
for _ in range(int(input())):
	(n, p) = map(int, input().split())
	if p >= n:
		print(1)
	else:
		z = n
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				if i <= p:
					z = min(z, n // i)
				if n // i <= p:
					z = min(z, i)
		print(z)


import sys
I = sys.stdin.readline
ans = ''

def is_prime(n):
	arr = []
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			arr.append((i, n // i))
	return arr
for _ in range(int(I())):
	(n, k) = map(int, I().split())
	if k >= n:
		ans += '1\n'
	else:
		x = is_prime(n)
		if len(x) == 0:
			ans += str(n) + '\n'
		else:
			y = n
			for i in x:
				if i[0] <= k:
					y = min(y, i[1])
				if i[1] <= k:
					y = min(y, i[0])
			ans += str(y) + '\n'
print(ans)


import math
t = int(input())

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

def solve(n, k):
	h = 1
	if k == 1:
		return n
	elif k >= n:
		return 1
	if isPrime(n):
		return n
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		if i > k:
			break
		if n % i == 0:
			if n // i <= k:
				return i
			h = i
	return n // h
for i in range(t):
	(n, k) = map(int, input().split())
	ans = solve(n, k)
	print(ans)


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	l = []
	i = 1
	while i * i <= n:
		if n % i == 0:
			if n == i * i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i += 1
	l.sort(reverse=True)
	for i in l:
		if i <= k:
			print(n // i)
			break


from math import sqrt
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, list(input().split())))
	if n <= k:
		print(1)
		continue
	if n % k == 0:
		print(n // k)
		continue
	ans = n
	for i in range(1, min(k, int(sqrt(n)) + 2)):
		if n % i:
			continue
		ans = min(n // i, ans)
		if n // i <= k:
			ans = min(ans, i)
	print(ans)


import heapq
from collections import *
import math

def solve():
	(n, k) = map(int, input().split())
	ans = n
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i <= k:
				ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
	print(ans)
t = int(input())
for _ in range(t):
	solve()


import math

def Divisors(n):
	ls = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				(ls.append(i),)
			else:
				ls.append(i)
				ls.append(n // i)
		i = i + 1
	return ls
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ls = Divisors(n)
	print(n // max([i for i in ls if i <= k]))


import math

def solve(n, k):
	ans = n
	for j in range(1, int(math.sqrt(n)) + 1):
		if n % j == 0:
			if j <= k:
				ans = min(ans, n // j)
			if n // j <= k:
				ans = min(ans, j)
	print(ans)
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	solve(n, k)


import math

def printDivisors(n, p):
	ans = 1
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				if p >= i > ans:
					ans = i
			else:
				if p >= i > ans:
					ans = i
				if p >= n // i > ans:
					ans = n // i
		i = i + 1
	return ans
for _ in range(int(input())):
	(m, k) = map(int, input().split())
	l = printDivisors(m, k)
	print(m // l)


from math import sqrt
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	ans = n
	for i in range(2, int(round(sqrt(n))) + 1):
		if n % i == 0:
			res1 = i
			res2 = n // i
			if n / i <= k:
				if res1 < ans:
					ans = res1
			if i <= k:
				if res2 < ans:
					ans = res2
	print(ans)


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 is_prime(n):
	if n < 2:
		return False
	sr = 1
	while sr ** 2 < n:
		sr += 1
	for i in range(2, sr + 1):
		if n % i == 0:
			return False
	return True

def defactor(n):
	factors = []
	for i in range(2, n + 1):
		while n != i:
			if n % i != 0:
				break
			factors.append(i)
			n = n // i
	factors.append(n)
	return factors

def buy_shovels(n, k):
	if k >= n:
		return 1
	i = 1
	ans = n
	while i ** 2 <= n:
		if n % i == 0:
			if n // i <= k:
				return i
			if i <= k:
				ans = n // i
		i += 1
	return ans

def main():
	t = inp()
	for _ in range(t):
		(n, k) = invr()
		ans = buy_shovels(n, k)
		print(ans)
main()


import sys
input = sys.stdin.readline
from collections import *

def make_divs(n):
	divs = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divs.append(i)
			if i != n // i:
				divs.append(n // i)
	return divs
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ds = make_divs(n)
	ans = 10 ** 18
	for d in ds:
		if d <= k:
			ans = min(ans, n // d)
	print(ans)


import math
import sys
input = sys.stdin.readline

def solve():
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
		return
	else:
		c = 2
		m1 = pow(10, 10)
		while c <= math.sqrt(n):
			if n % c == 0:
				v = n // c
				if k >= v:
					m1 = min(m1, c)
				if k >= c:
					m1 = min(m1, v)
			c += 1
		if m1 == pow(10, 10):
			print(n)
		else:
			print(m1)
for _ in range(int(input())):
	solve()


from sys import stdin, stdout
import sys
from math import *
input = stdin.readline

def c(n):
	f = [1]
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			if n % (n // i) == 0:
				f.append(n // i)
			f.append(i)
	f.append(n)
	f.sort()
	return f
for __ in range(int(input())):
	(n, k) = map(int, input().split())
	a = c(n)[::-1]
	ans = n
	for i in range(len(a)):
		if a[i] <= k:
			ans = n // a[i]
			break
	print(ans)


from sys import stdin
from math import sqrt
for case in range(int(stdin.readline())):
	(n, k) = [int(x) for x in stdin.readline().split()]
	if k >= n:
		print(1)
	else:
		valid = False
		if k >= sqrt(n):
			for x in range(1, int(sqrt(n)) + 1):
				if n % x == 0 and n // x <= k:
					print(x)
					valid = True
					break
		if not valid:
			for x in range(min(int(sqrt(n)), k), 0, -1):
				if n % x == 0:
					print(n // x)
					break


from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	T = int(input())
	for _ in [0] * T:
		(N, K) = map(int, input().split())
		ans = N
		for i in range(1, int(N ** 0.5) + 1):
			if not N % i:
				j = N // i
				if i <= K:
					ans = min(ans, N // i)
				if j <= K:
					ans = min(ans, N // j)
		print(ans)
main()


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	if k >= n:
		print(1)
	else:
		facs = []
		lim = min(int(n ** 0.5), k)
		for i in range(1, lim + 1):
			if n % i == 0:
				facs.append(i)
				tmp = n // i
				if tmp <= k:
					facs.append(tmp)
		mx = max(facs)
		print(n // mx)


def isprime(n):
	if n == 0 or n == 1:
		return False
	if n == 2:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if n % i == 0:
			return False
	return True

def fact(n):
	a = []
	for i in range(1, int(n ** (1 / 2)) + 1):
		if n % i == 0:
			a.extend([i, n // i])
	return a
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif isprime(n):
		print(n)
	else:
		x = fact(n)
		x = sorted(x)
		for i in x:
			if n // i <= k:
				print(i)
				break


def isPrime(n, k):
	i = 1
	ans = n
	while i * i <= n and i <= k:
		if n % i == 0:
			b = n // i
			if b > k:
				b = i
			m = min(n // i, n // b)
			ans = min(ans, m)
		i += 1
	return ans
for i in range(int(input())):
	(a, b) = map(int, input().split())
	print(isPrime(a, b))


def shovel(n, k):
	if k == 1:
		return n
	if k >= n:
		return 1
	res = n
	i = 2
	while i * i <= n:
		if n % i == 0:
			if i <= k:
				res = min(res, n // i)
			if n // i <= k:
				res = min(res, i)
		i += 1
	return res
for t in range(int(input())):
	(n, k) = map(int, input().split())
	print(shovel(n, k))


import math
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split(' ')))
	count = 1
	t = k
	if n <= k:
		print(1)
	else:
		t = []
		for i in range(1, math.floor(math.sqrt(n)) + 1):
			if n % i == 0:
				if i <= k:
					t.append(i)
				if n // i <= k:
					t.append(n // i)
		l = max(t)
		print(n // l)


import sys
from math import sqrt
input = sys.stdin.readline

def get_divisor(n):
	ret = set()
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			ret.add(i)
			ret.add(n // i)
	return sorted(ret)

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		if k >= n:
			print(1)
			continue
		arr = get_divisor(n)
		ret = -1
		for num in arr:
			if num > k:
				break
			ret = num
		print(n // ret)
main()


t = int(input(''))
for _ in range(t):
	[n, k] = list(map(int, input().split()))
	sol = n
	for i in range(1, 1000000000000):
		if n % i == 0:
			if i <= k:
				sol = min(sol, n // i)
			if n // i <= k:
				sol = min(sol, i)
		if i * i > n:
			break
	print(sol)


t = int(input())

def isprime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True
for i in range(t):
	(n, k) = map(int, input().split())
	if k == 1:
		print(n)
	elif n <= k:
		print(1)
	elif isprime(n) == True:
		print(n)
	else:
		l = []
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0 and i <= k:
				l.append(i)
				l.append(n // i)
		maxn = -1
		for i in l:
			if i <= k and (maxn == -1 or i > maxn):
				maxn = i
		print(n // maxn)


import math

def printDivisors(n, k):
	lis = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i and i <= k:
				lis.append(i)
			else:
				if i <= k:
					lis.append(i)
				if n // i <= k:
					lis.append(n // i)
		i = i + 1
	return lis
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	x = printDivisors(n, k)
	print(n // max(x))


def fact(a):
	for i in range(1, int(a ** 0.5 + 1)):
		if a % i == 0:
			if a // i != i:
				li.append(i)
				li.append(a // i)
			else:
				li.append(i)
a = int(input())
for _ in range(a):
	(x, y) = map(int, input().split())
	if y >= x:
		print(1)
	elif y == 1:
		print(x)
	elif x % y == 0:
		print(x // y)
	elif x > y:
		li = []
		fact(x)
		li.sort(reverse=True)
		for b in li:
			if b <= y:
				print(x // b)
				break


import math
from bisect import *

def get_divisors(n):
	large_divisors = []
	pfs = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			pfs.append(i)
			if i * i != n:
				large_divisors.append(int(n / i))
	large_divisors.reverse()
	return [*pfs, *large_divisors]
R = lambda : map(int, input().split())
(t,) = R()
while t:
	t -= 1
	(n, k) = list(R())
	div = get_divisors(n)
	id = bisect(div, k, 0, len(div)) - 1
	print(int(n / div[id]))


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	l = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	l.sort()
	for i in range(1, len(l)):
		if l[i] > k and l[i - 1] <= k:
			x = l[i - 1]
			break
	if k >= n:
		print(1)
	else:
		print(n // x)


import math
import bisect

def printDivisors(n):
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				a.append(i)
			else:
				a.extend([i, n // i])
		i = i + 1
	return a
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		a = []
		b = printDivisors(n)
		b.sort()
		t1 = bisect.bisect(b, k) - 1
		print(n // b[t1])


from math import sqrt
t = int(input())
while t:
	(n, k) = map(int, input().split())
	if k >= n:
		print('1')
	elif k == 1:
		print(n)
	else:
		a = []
		for i in range(1, int(sqrt(n)) + 1):
			if n % i == 0:
				a.append(i)
				if n // i != i:
					a.append(n // i)
		a.sort()
		for i in a:
			if n // i <= k:
				print(i)
				break
	t = t - 1


import math
t = int(input())
while t != 0:
	(n, k) = map(int, input().split())
	if k > n:
		print(1)
	else:
		list1 = list()
		for i in range(1, int(math.sqrt(n) + 1)):
			if n % i == 0:
				if i != n // i:
					list1.append(i)
					list1.append(n // i)
				else:
					list1.append(i)
		mini = n // list1[0]
		for i in range(len(list1)):
			p = n // list1[i]
			if mini > p and list1[i] <= k:
				mini = p
		print(mini)
	t -= 1


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a <= b:
		print(1)
	elif a % b == 0:
		print(a // b)
	elif a % 2 == 0 and b >= a // 2:
		print(2)
	elif b == 1:
		print(a)
	else:
		ans = a
		cur = 1
		while cur * cur <= a:
			if a % cur == 0:
				if cur <= b:
					ans = min(ans, a // cur)
				if a // cur <= b:
					ans = min(ans, cur)
			cur += 1
		print(ans)


import math

def fun(a, b):
	if a <= b:
		print(1)
		return
	if a > b:
		max = 1
		val = 0
		for i in range(1, math.floor(math.sqrt(a)) + 2):
			if a % i == 0 and i <= b and (a // i <= b):
				z = a // i
				print(a // z)
				return
			elif a % i == 0 and i <= b:
				val = i
			if max < val:
				max = val
		print(a // max)
		return
for i in range(0, int(input())):
	(a, b) = [int(x) for x in input().split()]
	fun(a, b)


def printDivisors(n):
	d = []
	i = 1
	while i <= n ** 0.5:
		if n % i == 0:
			if n / i == i:
				d.append(int(i))
			else:
				d.append(int(i))
				d.append(n // i)
		i = i + 1
	return d
tests = int(input())
div = 1
for _ in range(tests):
	(n, k) = map(int, input().split())
	z = k + 1
	d = printDivisors(n)
	div = 1
	for i in d:
		if i <= k:
			if i > div:
				div = i
	print(n // div)


t = int(input())
for k in range(t):
	(n, k) = map(int, input().rstrip().split())
	ans = 1
	if k == 1:
		print(n)
	elif n < k:
		print(1)
	else:
		i = 1
		while i <= int(n ** 0.5) + 1:
			if n % i == 0:
				if n // i <= k:
					ans = max(ans, n // i)
				if i <= k:
					ans = max(ans, i)
			i += 1
		print(n // ans)


from sys import stdin, stdout
from collections import Counter
from math import ceil
from bisect import bisect_left
from bisect import bisect_right
import math
ai = lambda : list(map(int, stdin.readline().split()))
ei = lambda : map(int, stdin.readline().split())
ip = lambda : int(stdin.readline().strip())

def checkPrime(n):
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	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(ip()):
	(n, k) = ei()
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		ans = 0
		j = 1
		while j * j <= n:
			if n % j == 0:
				if j <= k:
					ans = max(ans, j)
				if n // j <= k:
					ans = max(ans, n // j)
			j += 1
		print(n // ans)


n = int(input())

def divs(n):
	i = 1
	div = []
	while i * i <= n:
		if n % i == 0:
			div.append(i)
			div.append(n // i)
		i += 1
	return sorted(div)
for i in range(n):
	(n, k) = [int(s) for s in input().split()]
	if k >= n:
		print(1)
	else:
		for div in divs(n)[::-1]:
			if div <= k:
				print(n // div)
				break


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		print(n)
	elif k >= n:
		print(1)
	else:
		flag = 0
		l = []
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0:
				if i <= k:
					l.append(i)
					l.append(n // i)
		l = sorted(l, reverse=True)
		for i in l:
			if i <= k:
				flag = 1
				print(n // i)
				break
		if flag == 0:
			print(n)


import math
import sys
from collections import deque
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		l = []
		for d in range(1, int(math.sqrt(n) + 1)):
			if n % d == 0:
				if d <= k:
					l.append(n // d)
				if n // d <= k:
					l.append(d)
		print(min(l[:]))


import math

def large(n, k):
	arr = []
	i = 1
	while i <= int(math.sqrt(n)):
		if n % i == 0:
			if n // i == i:
				if i <= k:
					arr.append(i)
			else:
				if i <= k:
					arr.append(i)
				if n // i <= k:
					arr.append(n // i)
		i = i + 1
	return arr
t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	if k == 1:
		print(n)
	elif n <= k:
		print(1)
	elif n > k:
		l = large(n, k)
		if len(l) == 0:
			print(n)
		else:
			ff = n // max(l)
			print(ff)


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


import math
import bisect

def primefactor(n):
	div = 0
	a = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n % i == i:
				a.append(i)
			else:
				a.append(i)
				a.append(n // i)
	return a
t = int(input())
for ii in range(t):
	(n, k) = list(map(int, input().split()))
	if n <= k:
		print(1)
		continue
	a = primefactor(n)
	a.sort()
	index = bisect.bisect_right(a, k)
	print(n // a[index - 1])


t = int(input())
while t > 0:
	(n, c) = [int(i) for i in input().split(' ')]
	k = 1
	ans = 1
	z = int(n ** 0.5)
	while k <= z and k <= c:
		if n % k == 0:
			ans = max(k, ans)
			if n // k <= c:
				ans = max(ans, n // k)
			if n // ans <= c:
				ans = max(ans, n // ans)
		k += 1
	print(n // ans)
	t -= 1


import math
n = int(input())
for _ in range(n):
	(n, k) = list(map(int, input().split()))
	if n <= k:
		print(1)
	else:
		c = n
		for d in range(min(int(math.sqrt(n)), k), 0, -1):
			if n % d == 0:
				if n // d <= k:
					c = min(d, c)
				else:
					c = min(n // d, c)
		print(c)


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	(n, k) = map(int, sys.stdin.readline().split())
	list_num = []
	for i in range(1, int(n ** 0.5) + 1):
		if not n % i:
			list_num.append(i)
			if not i ** 2 == n:
				list_num.append(n // i)
	list_num.sort(reverse=True)
	for num in list_num:
		if num <= k:
			print(n // num)
			break


for _ in range(int(input())):
	mx = -1
	(n, k) = map(int, input().split())
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i <= k and i > mx:
				mx = i
				if n // i <= k and n // i > mx:
					mx = n // i
	print(n // mx)


import math

def findDivisors(n):
	ans = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				ans.append(i)
			else:
				ans.append(i)
				ans.append(n // i)
		i = i + 1
	return ans
t = int(input())
while t:
	t -= 1
	(n, k) = [int(i) for i in input().split()]
	if k >= n:
		print(1)
	else:
		a = findDivisors(n)
		a.sort()
		for i in range(len(a) - 1, -1, -1):
			if a[i] <= k:
				num = a[i]
				break
		print(n // num)


def main():
	import sys
	input = sys.stdin.readline
	sys.setrecursionlimit(10 ** 7)
	from collections import Counter, deque
	from itertools import combinations, permutations, accumulate, groupby, product
	from bisect import bisect_left, bisect_right
	from heapq import heapify, heappop, heappush
	import math
	t = int(input())

	def yakusuu(N):
		n = int(N ** 0.5) + 1
		res1 = []
		res2 = []
		for i in range(1, n):
			if N % i == 0:
				res1.append(i)
				if N != i ** 2:
					res2.append(N // i)
		res2.reverse()
		return res1 + res2
	for _ in range(t):
		(n, k) = map(int, input().split())
		l = yakusuu(n)
		for i in range(len(l) - 1, -1, -1):
			if l[i] <= k:
				print(n // l[i])
				break
main()


def is_prime(n):
	if n == 2:
		return True
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	return True
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		m = 1000000000
		i = 1
		while i * i <= n:
			if n % i == 0:
				if i <= k:
					m = min(m, n // i)
				if n // i <= k:
					m = min(m, i)
			i += 1
		print(m)


import math
for _ in range(int(input())):
	(N, K) = [int(x) for x in input().split()]
	if N <= K:
		print(1)
	else:
		arr = []
		for i in range(1, int(math.ceil(N ** 0.5)) + 1):
			if N % i == 0 and i <= K:
				arr.append(i)
				if N // i <= K:
					arr.append(N // i)
		print(N // max(arr))


T = int(input())
for t_itr in range(T):
	(N, K) = list(map(int, input().rstrip().split()))
	if N <= K:
		result = 1
	else:
		result = N
		for x in range(2, int(N ** 0.5) + 1):
			(d, m) = divmod(N, x)
			if m == 0:
				if d <= K:
					result = min(result, x)
				elif x <= K:
					result = min(result, d)
	print(result)


from math import sqrt
t = int(input())
while t:
	(n, k) = [int(x) for x in input().split()]
	lim = int(sqrt(n)) + 1
	answ = 1
	for i in range(1, lim):
		if n % i == 0:
			if n // i <= k:
				answ = max(answ, n // i)
			elif i <= k:
				answ = max(answ, i)
	print(n // answ)
	t -= 1


import sys
buff_readline = sys.stdin.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 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):
	ans = INF
	for d in divisor(N):
		if d <= K:
			ans = min(ans, N // d)
	return ans

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


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7
T = int(stdin.readline())
for _ in range(T):
	(n, k) = list(map(int, stdin.readline().split()))
	s = int(math.sqrt(n))
	mn = n + 1
	for i in range(1, s + 1):
		if n % i == 0:
			f1 = i
			f2 = n // i
			if f1 <= k:
				if f2 < mn:
					mn = f2
			if f2 <= k:
				if f1 < mn:
					mn = f1
	print(mn)


test_cases = int(input())
for z in range(test_cases):
	(n, k) = list(map(int, input().split()))
	if k >= n:
		print(1)
	else:
		ans = 10 ** 9
		count = 0
		for i in range(min(int(n ** 0.5), k)):
			i = min(int(n ** 0.5), k) - i
			if n % i == 0:
				ans = min(n // i, ans)
				if n // i <= k:
					ans = min(i, ans)
		print(ans)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	div = 1
	ans = 1
	while div <= k and div * div <= n:
		if n % div == 0:
			ans = max(ans, div)
			if n // div <= k:
				ans = max(ans, n // div)
		div += 1
	print(n // ans)


t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	li = []
	x = 0
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			li.insert(x, n // i)
			li.insert(x, i)
			x += 1
	a = 0
	for i in li:
		if n // i <= k:
			a = i
			break
	print(a)


from collections import Counter
from collections import defaultdict
from collections import deque
import math
import heapq
import sys
input = sys.stdin.readline
from bisect import *
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rls = lambda : list(map(str, input().split()))

def fact(n):
	s = set()
	x = 1
	while x * x <= n:
		if n % x == 0:
			s.add(x)
			s.add(n // x)
		x = x + 1
	s = list(s)
	return s
t = int(input())
for _ in range(0, t):
	(n, k) = rl()
	if n <= k:
		print(1)
	elif n % k == 0:
		print(n // k)
	else:
		factors = fact(n)
		factors.sort()
		ind = bisect_left(factors, k)
		for i in range(ind - 1, -1, -1):
			if n % factors[i] == 0:
				print(n // factors[i])
				break


import math

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

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

def find_factor(x, k):
	end = math.sqrt(x)
	i = 1
	ans = 0
	while i <= end:
		if x % i == 0:
			if i <= k:
				ans = max(ans, i)
			if n // i <= k:
				ans = max(ans, n // i)
		i += 1
	return ans
for _ in range(int(input())):
	(n, k) = multiple_input()
	if k >= n:
		print(1)
	else:
		print(n // find_factor(n, k))


import math

def primes(x):
	result = []
	for i in range(2, int(math.sqrt(x)) + 1):
		if x % i == 0:
			result.append(i)
			result.append(x // i)
	return result
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	result = primes(n)
	answer = n
	if n <= k:
		print(1)
	else:
		for x in result:
			if x <= k:
				answer = min(answer, n // x)
		print(answer)


import heapq
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	divisors = []
	loop = min(int(n ** 0.5) + 1, k + 1)
	for i in range(1, loop):
		if n % i == 0:
			if i <= k:
				divisors.extend([-i])
				x = n // i
				if i != x and x <= k:
					divisors.extend([-x])
	heapq.heapify(divisors)
	x = heapq.heappop(divisors)
	print(n // -x)


import math
t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split(' '))
	if n <= k:
		print(1)
	else:
		m = min(int(math.sqrt(n)), k)
		c = 1
		for i in range(2, m + 1):
			if n % i == 0:
				c = i
				d = n // i
				if d <= k:
					c = d
					break
		print(n // c)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = 10 ** 10
	for i in range(1, int(n ** 0.5 + 1)):
		if n % i == 0:
			if n // i <= k:
				a = i
				f = 1
				break
			elif i <= k:
				a = min(a, n // i)
	print(a)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	odp = []
	if k >= n:
		print(1)
	else:
		for i in range(1, int(n ** (1 / 2)) + 1):
			if n % i == 0:
				x = n / i
				y = n / x
				odp.append(x)
				odp.append(y)
			else:
				pass
		odp.sort()
		for j in range(len(odp)):
			if k < odp[j]:
				odp[j] = 1
			else:
				pass
		print(int(n // max(odp)))


from math import sqrt

def isprime(n):
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	elif isprime(n):
		print(n)
	else:
		ans = n
		for i in range(min(k, int(sqrt(n)) + 1), 0, -1):
			if n % i == 0:
				ans = min(ans, n // i)
				if n // i <= k:
					ans = min(ans, i)
		print(ans)


import math

def shovel(n, k):
	x = int(math.sqrt(n)) + 1
	ans = n
	for i in range(1, x + 1):
		if n % i == 0:
			if i <= k:
				ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
	return ans
t = int(input())
for i in range(0, t):
	nk = input().split()
	n = int(nk[0])
	k = int(nk[1])
	print(shovel(n, k))


import sys
import math
import heapq
import collections

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()
	ans = 0
	i = 1
	while i * i <= n:
		if n % i == 0 and i <= k and (i > ans):
			ans = i
		j = n // i
		if n % j == 0 and j <= k and (j > ans):
			ans = j
		i += 1
	print(n // ans)


from math import sqrt

def divisors(n):
	divs = {1}
	for i in range(2, int(sqrt(n)) + 5):
		if n % i == 0:
			divs.add(i)
			divs.add(n // i)
	divs |= {n}
	return divs

def main():
	(n, k) = map(int, input().split())
	ans = 1e+18
	for div in divisors(n):
		if div <= k:
			ans = min(ans, n // div)
	return ans
t = int(input())
for _ in range(t):
	print(main())


from math import *
from collections import *
from operator import itemgetter
import bisect
i = lambda : input()
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
I = lambda : list(map(int, input().split()))
chrIdx = lambda x: ord(x) - 96
idxChr = lambda x: chr(96 + x)
t = ii()
for _ in range(t):
	(n, k) = iia()
	if n <= k:
		print(1)
	else:
		i = 2
		ans = n
		while i ** 2 <= n:
			j = n // i
			if n % i == 0 and i <= k:
				ans = min(ans, n // i)
			if n % i == 0 and j <= k:
				ans = min(ans, n // j)
			i += 1
		print(ans)


import math

def Divisors(n):
	i = 1
	l = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	l.sort(reverse=True)
	return l
t = int(input())
for _ in range(t):
	(m, n) = map(int, input().split())
	if m <= n:
		print('1')
	else:
		l = Divisors(m)
		for i in l:
			if i <= n:
				print(m // i)
				break


t = int(input())
from math import *

def primes(n):
	k = []
	for tz in range(1, ceil(sqrt(n)) + 1):
		if n % tz == 0:
			if n // tz == tz:
				k.append(tz)
			else:
				k.append(tz)
				k.append(n // tz)
	return k
for xy in range(t):
	(x, y) = list(map(int, input().split()))
	tl = primes(x)
	if y >= x:
		print(1)
		continue
	prod = 1
	for ay in tl:
		if ay <= y and ay > prod:
			prod = ay
	print(x // prod)


from sys import stdin, stdout
import collections
import heapq
import itertools
import functools
import math
import operator

def read_line():
	return stdin.readline().strip()

def read_int():
	return int(read_line())

def read_arr():
	return read_line().split(' ')

def read_int_arr():
	return [int(x) for x in read_arr()]

def query_interactive(s):
	print(s)
	stdout.flush()

def main():
	T = 1
	T = read_int()
	for _ in range(T):
		(n, k) = read_int_arr()
		best = n
		for i in range(1, math.ceil(math.sqrt(n)) + 1):
			if n % i != 0:
				continue
			bucket_size = n // i
			if bucket_size <= k:
				best = min(best, i)
			(i, bucket_size) = (bucket_size, i)
			if bucket_size <= k:
				best = min(best, i)
		print(best)
main()


import math

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

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

def solve():
	(n, k) = list(map(int, input().split(' ')))
	arr = sorted(getFactors(n))
	for i in arr[::-1]:
		if i <= k:
			print(n // i)
			return
main()


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())
	if k >= n:
		print(1)
	else:
		l = []
		s = int(sqrt(n))
		for i in range(2, s + 2):
			if n % i == 0 and i <= k:
				l.append(n // i)
				t = n // i
				if t <= k:
					l.append(n // t)
		if len(l) == 0:
			print(n)
		else:
			print(min(l))


from math import sqrt
from sys import stdin
input = stdin.readline

def main():
	test = int(input())
	for t in range(test):
		l = [int(i) for i in input().split(' ')]
		n = l[0]
		k = l[1]
		val = min(int(sqrt(n)), k)
		if n <= k:
			print(1)
		else:
			i = 1
			m = n
			while i <= val:
				if n % i == 0:
					if n // i <= k:
						m = min(n // i, i, m)
					else:
						m = min(n // i, m)
				i += 1
			print(m)
main()


a = int(input())
for i in range(0, a):
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	if y == 1:
		print(x)
	elif x <= y:
		print(1)
	else:
		found = 0
		l = int(x ** 0.5) + 1
		mini = min(l, y)
		for j in range(1, mini + 1):
			if x % j == 0:
				if x // j <= y:
					found = 1
					print(j)
					break
				else:
					val = x // j
		if found == 0:
			print(val)


I = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	(n, k) = I()
	an = 0
	if k >= n:
		print(1)
		continue
	an = n
	i = 2
	while i <= n ** 0.5 and i <= k:
		if n % i == 0:
			an = min(an, n // i) if n // i > k else min(an, i)
		i += 1
	print(an)


t = int(input())
l = []
for i in range(t):
	(m, n) = list(map(int, input().split()))
	l.append([m, n])
for j in l:
	if j[1] == 1:
		print(j[0])
	elif j[1] >= j[0]:
		print(1)
	else:
		md = 1
		for k in range(1, int(j[0] ** (1 / 2)) + 1):
			if j[0] % k == 0:
				if k >= md and k <= j[1]:
					md = k
				if j[0] // k >= md and j[0] // k <= j[1]:
					md = j[0] // k
		print(j[0] // md)


def solve(n, k):
	x = n
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i <= k:
				x = min(x, n // i)
			if n // i <= k:
				x = min(x, i)
	return x
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(solve(n, k))


total_case = int(input())
for i in range(total_case):
	line = input().split()
	(n, k) = (int(line[0]), int(line[1]))
	if n <= k:
		print(1)
		continue
	maxd = int(n ** 0.5)
	best = n
	for d in range(1, maxd + 1):
		if n % d == 0:
			result = int(n / d)
			if d <= k:
				best = min(result, best)
			if result <= k:
				best = min(best, d)
	print(best)


def factors(n):
	return set((factor for i in range(1, int(n ** 0.5) + 1) if n % i == 0 for factor in (i, n // i)))
t = int(input())
for we in range(t):
	(n, k) = map(int, input().split())
	g = sorted(list(factors(n)))
	a = 0
	i = 0
	while n // g[i] > k:
		i += 1
	print(g[i])


import sys
import math

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

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

def printspx(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')

def printchk(*args):
	return print(*args, end=' \\ ')
MODPRIME = int(1000000000.0 + 7)
BABYMOD = 998244353
for _testcases_ in range(int(input())):
	(n, k) = get_ints()
	if k >= n:
		print('1')
	else:
		mx = 1
		for i in range(1, math.floor(math.sqrt(n)) + 1):
			if n % i == 0:
				if i <= k:
					mx = max(mx, i)
				if n // i <= k:
					mx = max(mx, n // i)
		print(n // mx)


from collections import defaultdict
from collections import OrderedDict
from collections import deque
import bisect
import math
import heapq
import sys
import io, os
for ii in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	if k == 1:
		print(n)
		continue
	temp = n
	i = 2
	f = 0
	while i <= math.ceil(n ** 0.5):
		if i > k:
			break
		if n % i == 0:
			temp = min(temp, n // i)
			f = 1
			if n // i <= k:
				f = 1
				temp = min(temp, i)
		i += 1
	if not f:
		print(n)
		continue
	print(temp)


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

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

def prime_factors(n):
	i = 2
	while i * i <= n:
		if n % i == 0:
			n /= i
			yield i
		else:
			i += 1
	if n > 1:
		yield n

def prod(iterable):
	result = 1
	for i in iterable:
		result *= i
	return result

def get_divisors(n):
	pf = prime_factors(n)
	pf_with_multiplicity = collections.Counter(pf)
	powers = [[factor ** i for i in range(count + 1)] for (factor, count) in pf_with_multiplicity.items()]
	for prime_power_combo in itertools.product(*powers):
		yield int(prod(prime_power_combo))
t = int(input())
for _ in range(t):
	(n, k) = iis()
	divs = sorted(list(get_divisors(n)))[::-1]
	for i in divs:
		if i <= k:
			print(n // i)
			break


import sys, math

def input():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		ans = n
		for i in range(1, 1 + int(math.sqrt(n))):
			if n % i == 0:
				if n // i <= k:
					ans = min(ans, i)
				if i <= k:
					ans = min(ans, n // i)
		print(ans)
main()


import math

def fact(x):
	ans = []
	for i in range(1, int(math.sqrt(x)) + 1):
		if x % i == 0:
			if x // i == i:
				ans.append(i)
			else:
				ans.append(x // i)
				ans.append(i)
	ans.sort()
	return ans
a = int(input())
for i in range(a):
	(x, y) = map(int, input().split())
	ans = fact(x)
	flag = 0
	for i in range(len(ans) - 1, -1, -1):
		if ans[i] <= y:
			print(x // ans[i])
			flag = 1
			break
	if flag == 1:
		continue


import os
import sys
from io import BytesIO, IOBase
import math
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 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
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a <= b:
		print('1')
	elif b == 1:
		print(a)
	else:
		ans = a
		if isPrime(a):
			print(a)
		else:
			k = int(a ** 0.5)
			m = min(k, b) + 1
			for i in range(1, m):
				if a % i == 0:
					ans = min(ans, a // i)
					if a // i <= b:
						ans = min(ans, a // (a // i))
			print(ans)


kl = int(input())
for l in range(kl):
	(n, k) = map(int, input().split())
	if n % k == 0:
		print(n // k)
	elif n <= k:
		print(1)
	else:
		t = min(k, int(n ** 0.5))
		ans = n
		for i in range(t):
			if n % (t - i) == 0:
				if max(t - i, n // (t - i)) <= k:
					ans = min(ans, min(t - i, n // (t - i)))
				else:
					ans = min(ans, max(t - i, n // (t - i)))
		print(ans)


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	ans = 100000000000
	o = int(math.sqrt(n))
	for j in range(1, o + 1):
		if n % j == 0:
			if j <= k:
				ans = min(ans, n // j)
			if n // j <= k:
				ans = min(ans, j)
	print(ans)


import math

def prime(p):
	if p == 1:
		return 0
	if p == 2 or p == 3:
		return 1
	if p % 2 == 0 or p % 3 == 0:
		return 0
	for i in range(5, int(math.sqrt(p)) + 1, 6):
		if p % i == 0 or p % (i + 2) == 0:
			return 0
	return 1
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	elif prime(n):
		print(n)
	else:
		minipack = math.inf
		for i in range(1, min(int(math.sqrt(n)) + 1, k + 1)):
			if n % i == 0:
				minipack = n // i
				if n // i <= k:
					minipack = i
					break
		print(minipack)


t = int(input())
for i in range(t):
	[n, k] = list(map(int, input().split()))
	f = True
	if k >= n:
		print(1)
	elif n % k == 0:
		print(n // k)
	elif n ** 0.5 >= k:
		t = 1
		for j in range(2, k):
			if n % j == 0:
				t = j
		print(n // t)
	elif n ** 0.5 < k:
		f = False
		t = 1
		m = -1
		for j in range(2, int(n ** 0.5) + 1):
			if n % j == 0:
				t = j
				if n // j <= k and m == -1:
					m = j
					f = True
					break
		if f:
			print(m)
		else:
			print(n // t)


import math
t = int(input())
for i in range(0, t):
	(b, c) = map(int, input().split())
	if b <= c:
		print(1)
	else:
		yak = []
		mn = 999999999
		k = 0
		for j in range(1, int(math.sqrt(b)) + 1):
			if b % j == 0:
				yak.append(j)
		length = len(yak)
		for k in range(length - 1, -1, -1):
			yak.append(b // yak[k])
		for kt in range(len(yak)):
			if c < yak[kt]:
				print(b // yak[kt - 1])
				break


for j in range(int(input())):
	(n, k) = map(int, input().split())
	i = 1
	l = []
	p = []
	while i * i <= n:
		if n % i == 0:
			l.append(i)
			if n // i != i:
				l.append(n // i)
		i += 1
	l.sort()
	if n <= k:
		print(1)
	else:
		i = 0
		while k >= l[i]:
			if k < l[i + 1] and k >= l[i]:
				a = l[i]
				break
			i += 1
		print(n // a)


import sys
import math
input = sys.stdin.readline

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
for _ in range(inin()):
	(n, k) = cin()
	ans = 1
	if n <= k:
		print(1)
	else:
		f = 0
		for i in range(1, int(math.sqrt(n)) + 1):
			if n % i == 0:
				if n // i <= k:
					ans = max(n // i, ans)
				if i <= k:
					ans = max(ans, i)
		print(n // ans)


import math

def printDivisors(n):
	a = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				a.append(int(i))
			else:
				a.append(int(i))
				a.append(int(n / i))
		i = i + 1
	return a
for i in range(int(input())):
	(n, k) = map(int, input().split())
	y = 0
	if n <= k:
		print(1)
	else:
		t = sorted(printDivisors(n))
		t.reverse()
		for i in range(len(t)):
			if t[i] <= k:
				y = n // t[i]
				break
		print(y)


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')
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = []
	for j in range(1, int(n ** 0.5) + 1):
		if n % j == 0:
			l.append(j)
			if j != n // j:
				l.append(n // j)
	l.sort()
	for j in range(len(l) - 1, -1, -1):
		if n % l[j] == 0 and l[j] <= k:
			print(n // l[j])
			break


t = int(input())
count = 0
while count < t:
	count += 1
	l = list(map(int, input().split(' ')))
	n = l[0]
	k = l[1]
	if k >= n:
		print(1)
	else:
		l = []
		factor = 1
		while factor <= n ** 0.5:
			if n % factor == 0:
				l.append(factor)
			factor += 1
		m = list(map(lambda x: n / x, l))
		m = m + l[::-1]
		for i in m:
			if i <= k:
				print(int(n / i))
				break


for z in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		i = 1
		ans = 10 ** 9 + 5
		while i * i <= n and i <= k:
			if n % i == 0:
				if n // i <= k:
					ans = min(ans, i)
				if n // i > k:
					ans = min(ans, n // i)
			i += 1
		print(ans)


from math import *
from sys import stdin, stdout
input = stdin.buffer.readline
t = int(input())
while t > 0:
	(a, b) = [int(x) for x in input().split()]
	d = []
	for i in range(1, int(sqrt(a)) + 1):
		if a % i == 0:
			if a // i == i:
				d.append(i)
			else:
				d.append(i)
				d.append(a // i)
	d.sort(reverse=True)
	for i in range(len(d)):
		if d[i] <= b:
			print(a // d[i])
			break
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = int(n ** 0.5)
	m = -float('inf')
	for i in range(1, s + 1):
		if n % i == 0:
			if i <= k:
				m = max(m, i)
			if n // i <= k:
				m = max(m, n // i)
	print(n // m)


from sys import stdin, stdout
from math import sqrt, floor
t = int(stdin.readline().strip())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	l = floor(sqrt(n)) + 1
	ans = None
	i = 1
	while i < l:
		if i > k:
			if ans:
				ans = n // ans
			break
		if n % i == 0:
			ans = i
			if n // i <= k:
				break
		i += 1
	else:
		if ans:
			ans = n // ans
		else:
			ans = n
	stdout.write('{}\n'.format(ans))


def main():
	for __ in [0] * int(input()):
		(n, k) = map(int, input().split())
		div = []
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				div.append(i)
				div.append(n // i)
		div.sort(reverse=True)
		for d in div:
			if d > k:
				continue
			else:
				print(n // d)
				break
main()


import sys
import os
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')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	lst = []
	for i in range(n):
		temp = [default] * m
		lst.append(temp)
	return lst

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}
from math import floor

def solve(n, k):
	res = []
	for i in range(floor(n ** 0.5), 0, -1):
		if n % i == 0 and i <= k:
			ans = n // i
			if n // i <= k:
				ans = min(ans, i)
			res.append(ans)
	return min(res)
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	print(solve(n, k))


import math

def c(n):
	l = []
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			l += [i]
			l += [n // i]
	if l == []:
		l += [1, n]
	return l

def main():
	for _ in range(int(input())):
		(n, k) = tuple(map(int, input().split()))
		l = c(n)
		l.sort()
		for i in range(len(l) - 1, -1, -1):
			if l[i] <= k:
				print(n // l[i])
				break
main()


t = int(input())
for w in range(t):
	nk = list(map(int, input().strip().split()))
	n = nk[0]
	k = nk[1]
	x = 1
	ans = n
	while x * x <= n and x <= k:
		if n % x == 0:
			if n // x <= k:
				ans = x
				break
			ans = min(ans, n // x)
		x += 1
	print(ans)


import sys
from math import ceil
TEST = 0
if TEST == 1:
	input_file = open('inputD.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()
for test in range(t):
	(n, k) = read_ints()
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		p = 0
		d = 1
		while d * d <= n:
			if n % d == 0:
				if d <= k:
					p = max(p, d)
				if n / d <= k:
					p = max(p, n / d)
			d += 1
		print(int(n / p))


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]
	k = m[i][1]
	tmp = n
	if n <= k:
		print(1)
	else:
		for j in range(ceil(sqrt(n)) + 5):
			if n % (j + 2) == 0:
				if j + 2 <= k and n / (j + 2) <= k:
					tmp = min(tmp, j + 2, floor(n / (j + 2)))
				elif j + 2 <= k:
					tmp = min(tmp, floor(n / (j + 2)))
				elif n / (j + 2) <= k:
					tmp = min(tmp, j + 2)
		print(tmp)


from math import sqrt

def divisors(n):
	result = []
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				result.append(i)
			else:
				result.append(i)
				result.append(n / i)
	return result
n = int(input())
for i in range(n):
	(x, y) = [int(x) for x in input().split()]
	l = [x / i for i in divisors(x) if i <= y]
	print(int(min(l)))


t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	i = 1
	res = n
	while i * i <= n:
		if n % i == 0:
			if k >= i:
				res = min(res, n // i)
			if n // i <= k:
				res = min(res, i)
		i += 1
	print(res)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	elif k == 1:
		print(n)
	else:
		ans = 1000000000
		for i in range(int(math.sqrt(n)), 1, -1):
			if n % i == 0:
				if i <= k:
					ans = min(ans, n // i)
				if n // i <= k:
					ans = min(ans, n // (n // i))
		if ans == 1000000000:
			print(n)
		else:
			print(ans)


import math
T = int(input())
for _ in range(0, T):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		ans = n
		i = 2
		while i <= int(math.sqrt(n)) + 1:
			if n % i == 0:
				if n // i == i:
					if i <= k:
						ans = min(ans, i)
				else:
					if i <= k:
						ans = min(ans, n // i)
					if n // i <= k:
						ans = min(ans, i)
			i = i + 1
		print(ans)


from math import sqrt
for i in range(int(input())):
	(n, k) = map(int, input().split())
	flag = False
	if n <= k:
		print(1)
		continue
	de = -1
	for j in range(1, min(k + 1, int(sqrt(n) + 1))):
		if n % j == 0:
			de = max(de, j)
			if n // j <= k:
				de = max(de, n // j)
	if de == -1:
		print(n)
	else:
		print(n // de)


from math import sqrt
from bisect import bisect_left
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if sqrt(n) > k:
		temp = k
	else:
		temp = sqrt(n)
		temp = int(temp)
	p = []
	for i in range(1, temp + 1):
		if n % i == 0:
			if n / i == i:
				p.append(i)
			else:
				p.append(i)
				p.append(n // i)
	p.sort()
	if k in p:
		print(n // k)
	else:
		temp = p[bisect_left(p, k) - 1]
		print(n // temp)


tests = int(input())
for i in range(tests):
	numbers = input().split()
	n = int(numbers[0])
	k = int(numbers[1])
	if k >= n:
		print(1)
	elif k == 1:
		print(n)
	else:
		result = 1
		for x in range(2, k + 1, 1):
			if n % x == 0:
				if n // x <= k:
					result = n // x
					break
				else:
					result = x
			if x * x > n:
				break
		print(n // result)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		v = []
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				if i != n // i:
					v.append(i)
					v.append(n // i)
				else:
					v.append(i)
		v.sort()
		import bisect
		a = bisect.bisect_right(v, k)
		b = v[a - 1]
		print(n // b)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k == 1:
		print(n)
		continue
	if k >= n:
		print(1)
		continue
	else:
		i = 1
		flag = 0
		temp = []
		while i <= math.sqrt(n):
			if n % i == 0:
				if n / i == i:
					if i <= k:
						print(i)
						flag = 1
						break
				else:
					div = n / i
					if div <= k:
						print(i)
						flag = 1
						break
					else:
						temp.append(i)
			i = i + 1
		if flag == 0:
			for x in temp[::-1]:
				if x <= k:
					print(n // x)
					flag == 1
					break


from fractions import Fraction
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 input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

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

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

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 = 1
for _ in range(iinput()):
	(n, k) = rinput()
	if k >= n:
		print(1)
	else:
		j = 1
		ans = 9999999999999999
		while j * j <= n:
			if n % j == 0:
				if n // j <= k:
					ans = min(ans, j)
				if j <= k:
					ans = min(ans, n // j)
			j += 1
		print(ans)


import math as mt
import sys, string
input = sys.stdin.readline
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()
	if n <= k:
		print(1)
	else:
		l = []
		for i in range(1, int(mt.sqrt(n)) + 1):
			if n % i == 0:
				if i <= k:
					l.append(i)
				if n // i <= k:
					l.append(n // i)
		ans = 10 ** 10
		for i in range(len(l)):
			ans = min(ans, n / l[i])
		print(int(ans))


from sys import stdin
import math

def readline():
	return stdin.readline()
tests = int(readline())

def solve(n, k):
	if n <= k:
		return 1
	sqr = min(math.ceil(math.sqrt(n)), k) + 1
	ans = n
	for i in range(1, sqr):
		if n % i == 0:
			ans = min(n // i, ans)
			r = n // i
			if r <= k:
				ans = min(n // r, ans)
	return ans
for t in range(0, tests):
	(n, k) = map(int, readline().split(' '))
	print(solve(n, k))


from sys import stdin, stdout
import math
n = int(stdin.readline())
for i in range(n):
	arr = [int(x) for x in stdin.readline().split()]
	ans = 1
	for i in range(1, int(math.sqrt(arr[0]) + 1)):
		if arr[0] % i == 0:
			if i <= arr[1]:
				ans = max(ans, i)
			if arr[0] / i <= arr[1]:
				ans = max(ans, arr[0] / i)
	stdout.write(str(int(arr[0] / ans)) + '\n')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	factors = []
	for j in range(1, n):
		if j * j > n:
			break
		if n % j == 0:
			factors.append(j)
			r = n // j
			if (r + 1) * j <= n:
				r += 1
			factors.append(r)
	factors.sort()
	factors.reverse()
	for j in factors:
		if j <= k:
			r = j
			break
	ans = n // r
	if (ans + 1) * r <= n:
		ans += 1
	print(max(1, ans))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = []
	i = 1
	while i * i <= n:
		if n % i == 0:
			arr.append(n // i)
			arr.append(i)
		i += 1
	if n == k:
		arr.append(n)
	arr.sort()
	x = 0
	for i in range(len(arr) - 1, -1, -1):
		if k >= arr[i]:
			x = n // arr[i]
			break
	print(x)


from math import sqrt, ceil

def find_shovel(n, k):
	if k >= n:
		return 1
	res = n
	for i in range(2, min(k, ceil(sqrt(n))) + 1):
		if n % i == 0:
			division = n // i
			if division <= k:
				return i
			res = min(res, division)
	return res
results = []
for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split(' ')]
	results.append(str(find_shovel(n, k)))
print('\n'.join(results))


t = int(input())
arr = []
for i in range(t):
	arr.append(list(map(int, input().split())))

def is_prime(n):
	if n % 2 == 0:
		return n == 2
	d = 3
	while n % d != 0:
		if d ** 2 > n:
			return True
		d += 2
	return d == n

def pack_count(n, k):
	if k >= n:
		return 1
	d = 2
	last_success = n
	while d <= k:
		if n % d == 0:
			last_success = n // d
			if last_success <= k:
				return d
		if d ** 2 > n:
			break
		d += 1
	return last_success
for item in arr:
	print(pack_count(item[0], item[1]))


import math
t = int(input())
while t > 0:
	inp = input().split()
	(n, k) = (int(inp[0]), int(inp[1]))
	if k >= n:
		print(1)
	else:
		check = 0
		ans = n
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0:
				if i <= k:
					ans = min(ans, int(n / i))
				if int(n / i) <= k:
					ans = min(ans, i)
		print(ans)
	t -= 1


import math
T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	found = False
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0 and n / i <= k:
			print(i)
			found = True
			break
	if found:
		continue
	for i in reversed(range(2, int(math.sqrt(n)) + 1)):
		if n % i == 0 and i <= k:
			print(int(n / i))
			found = True
			break
	if not found:
		print(n)


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())
	ans = math.inf
	for i in range(1, math.ceil(math.sqrt(n)) + 1):
		if i > k:
			break
		if n % i == 0:
			if n // i <= k:
				ans = min(ans, i)
			else:
				ans = min(ans, n // i)
	print(ans)


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'
pi = 3.141592653589793

def div(n, k):
	l = []
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				if i <= k:
					l.append(i)
			else:
				if i <= k:
					l.append(i)
				if n // i <= k:
					l.append(n // i)
	c = max(l)
	return c

def main():
	for _ in range(ii()):
		(n, k) = mi()
		ans = div(n, k)
		print(n // 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()


import math

def solve(n, k):
	i = 1
	c = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if i > c and i <= k:
				c = i
			if n // i > c and n // i <= k:
				c = n // i
		if i > k:
			break
		i = i + 1
	return n // c
tc = int(input())
while tc:
	(x, y) = map(int, input().split())
	if x <= y:
		print('1')
	else:
		print(solve(x, y))
	tc -= 1


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			divisors.append(n // i)
	d = 1
	for x in divisors:
		if x > d and x <= k:
			d = x
	print(n // d)


from math import ceil

def solve(n, k):
	if k >= n:
		return 1
	a = 2
	b = n
	while a < ceil(n ** 0.5) + 1 and a <= k:
		if n % a == 0:
			if n // a <= k:
				return a
			b = n // a
		a += 1
	return b
t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	ans = solve(n, k)
	print(ans)


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())
	d = make_divisors(n)
	ans = 10 ** 18
	for a in d:
		if 1 <= a <= k:
			ans = min(ans, n // a)
	print(ans)


import sys
max_int = 1000000001
min_int = -max_int
prime = []
t = int(input())
for _t in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	if k >= n:
		print(1)
		continue
	d = 2
	max_devider = 0
	while d * d <= n:
		if n % d == 0:
			if n // d <= k:
				print(d)
				break
			elif d <= k:
				max_devider = d
		d += 1
	else:
		if max_devider:
			print(n // max_devider)
		else:
			print(n)


def findfactors(n, k):
	if k == 1:
		return n
	if n <= k:
		return 1
	mini = n + 1
	for i in range(1, min(k + 1, int(n ** 0.5) + 1)):
		if n % i == 0:
			if n // i <= k:
				mini = min(mini, i)
			else:
				mini = min(mini, n // i)
	return mini
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(findfactors(n, k))


from sys import stdin
import math
t = int(stdin.readline())
while t:
	t -= 1
	(n, k) = map(int, stdin.readline().split())
	if k >= n:
		pack = 1
	else:
		pack = n
		for i in range(2, int(math.sqrt(n)) + 1):
			if n % i == 0:
				if i <= k:
					pack = min(pack, n // i)
				if n // i <= k:
					pack = min(pack, i)
	print(pack)


import sys, math

def printDivisors(n):
	i = 1
	a = []
	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
t = int(input())
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	c = printDivisors(n)
	c.sort(reverse=True)
	for i in range(len(c)):
		if c[i] <= k:
			print(n // c[i])
			break


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

def divisors(n):
	div = set([n])
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			div.add(i)
			div.add(n // i)
	return div
tc = ii1()
for _ in range(tc):
	(n, k) = iia()
	fact = sorted(list(divisors(n)), reverse=True)
	for i in fact:
		if i <= k and n % i == 0:
			print(n // i)
			break


import math

def answer(n, k):
	if n <= k:
		return 1
	max_div = 1
	for i in range(2, int(math.sqrt(n)) + 1):
		if i > k:
			break
		if n % i == 0:
			if n // i <= k:
				max_div = max(max_div, n // i)
			else:
				max_div = max(max_div, i)
	return n // max_div
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	print(answer(n, k))


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
import math
t = int(input())
for z in range(t):
	(n, k) = [int(i) for i in input().split()]
	if n <= k:
		print(1)
	elif isPrime(n):
		print(n)
	elif k == 1:
		print(n)
	else:
		i = 1
		d = []
		while i <= math.sqrt(n):
			if n % i == 0:
				if n / i == i:
					if i <= k:
						d.append(i)
				else:
					if i <= k:
						d.append(i)
					if n / i <= k:
						d.append(n / i)
			i = i + 1
		print(int(n / max(d)))


def SieveOfEratosthenes(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i == 0:
			factors.append(i)
			factors.append(n // i)
		i += 1
	return factors
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		factors = SieveOfEratosthenes(n)
		if len(factors) == 0:
			print(n)
		else:
			factors.sort()
			i = len(factors) - 1
			while factors[i] > k and i >= 0:
				i -= 1
			if i < 0:
				print(n)
			else:
				print(n // factors[i])


import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	count = 0
	c = 0
	a = [1]
	package = 1
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			count = 1
			x = n // i
			if x <= m:
				count = 2
				print(n // x)
				break
			elif i <= m:
				package = x
	if count != 2:
		print(package)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
		continue
	a = n
	for i in range(2, int(n ** (1 / 2)) + 1):
		if n % i == 0 and n // i <= k:
			print(i)
			break
		elif n % i == 0 and i <= k:
			a = n // i
	else:
		print(a)


import math

def is_prime(n, k):
	res = n
	if n == 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0 and n // i <= k:
			res = min(res, i)
		if n % i == 0 and i <= k:
			res = min(n // i, res)
	return res

def inp():
	ls = list(map(int, input().split()))
	return ls
t = int(input())
for ii in range(t):
	(n, k) = map(int, input().split())
	if n <= k:
		print(1)
	else:
		ans = is_prime(n, k)
		if ans == 0:
			print(n)
		else:
			print(ans)


from math import ceil, sqrt
T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	if K >= N:
		print(1)
		continue
	last_factor = 1
	for i in range(2, min(K + 1, ceil(sqrt(N)) + 1)):
		if N % i == 0:
			if N // i <= K:
				last_factor = N // i
				break
			else:
				last_factor = i
	print(N // last_factor)


import sys
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	t = sys.maxsize
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0 and i <= k:
			t = min(t, n // i)
		if n % i == 0 and n / i <= k:
			t = min(t, i)
	print(t)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	ans = float('inf')
	i = 1
	while i * i <= n:
		if not n % i:
			if i <= k:
				ans = min(ans, n // i)
			if n // i <= k:
				ans = min(ans, i)
		i += 1
	print(ans)


from math import sqrt as sq
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
	else:
		ans = 100000000000
		for i in range(1, int(sq(n)) + 2, 1):
			if n % i == 0:
				a = n // i
				if i <= k:
					ans = min(ans, n // i)
				if a <= k:
					ans = min(ans, n // a)
		print(ans)


t = int(input())

def rasl(n):
	ans = set()
	for i in range(2, int(round(n ** 0.5)) + 1):
		if n % i == 0:
			ans.add(i)
			ans.add(n // i)
	if len(ans) == 0:
		return [1]
	else:
		return list(ans)
for _ in range(t):
	(n, k) = map(int, input().split())
	if k >= n:
		print(1)
		continue
	best = 1
	for a in rasl(n):
		if a <= k and a > best:
			best = a
	print(n // best)


from math import *
t = int(input())
for i in range(t):
	arr = list(map(int, input().split()))
	n = arr[0]
	k = arr[1]
	ans = -1
	val = int(sqrt(n)) + 1
	for j in range(val):
		if j > 0 and n % j == 0:
			x = j
			y = n / j
			if x <= k:
				ans = max(ans, x)
			if y <= k:
				ans = max(ans, y)
	final = int(n / ans)
	print(final)