AtCoder Beginner Contest 112 - Partition

You are given integers N and M.
Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 10^5
 - N \leq M \leq 10^9

-----Input-----
Input is given from Standard Input in the following format:
N M

-----Output-----
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition.

-----Sample Input-----
3 14

-----Sample Output-----
2

Consider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common divisor is 2, and this is the maximum value.

Source: atcoder | Difficulty: MEDIUM


Solutions:
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]
(n, m) = map(int, input().split())
ans = 0
for i in make_divisors(m):
	if m // i >= n:
		ans = i
print(ans)


(n, m) = map(int, input().split())
(a, r) = divmod(m, n)
while True:
	r = m % a
	if r == 0:
		break
	a -= 1
print(a)


def resolve():
	(N, M) = map(int, input().split())
	ans = 1
	for A in range(1, int(M ** 0.5) + 1):
		if M % A != 0:
			continue
		B = M // A
		if N * A <= M:
			ans = max(ans, A)
		if N * B <= M:
			ans = max(ans, B)
	print(ans)

def __starting_point():
	resolve()
__starting_point()


def main():
	(N, M) = map(int, input().split())
	for g in range(M // N, 0, -1):
		if M % g == 0:
			print(g)
			return
main()


import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda : sys.stdin.readline().strip()
NI = lambda : int(input())
NMI = lambda : map(int, input().split())
NLI = lambda : list(NMI())
SI = lambda : input()

def make_grid(h, w, num):
	return [[int(num)] * w for _ in range(h)]

def main():
	(N, M) = NMI()
	yak = set()
	i = 1
	while i * i <= M:
		if M % i == 0:
			yak.add(i)
			yak.add(M // i)
		i += 1
	yak = sorted(list(yak), reverse=True)
	for y in yak:
		if y * N <= M:
			print(y)
			return

def __starting_point():
	main()
__starting_point()


def main():
	(N, M) = map(int, input().split(' '))
	for i in range(M // N, 0, -1):
		if M % i == 0 and i <= M / N:
			print(i)
			break
main()


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
(N, M) = (int(i) for i in input().split())
M_div = make_divisors(M)
div_rev = M_div[::-1]
for i in range(len(M_div)):
	if N <= M_div[i]:
		print(div_rev[i])
		break


def divisor(n):
	i = 1
	res = set()
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.add(i)
			res.add(n // i)
	return res

def main():
	(n, m) = map(int, input().split())
	md = list(divisor(m))
	md.sort(reverse=True)
	for i in md:
		if i * n <= m:
			print(i)
			return

def __starting_point():
	main()
__starting_point()


def f():
	(n, m) = map(int, input().split())
	for i in range(m // n, 0, -1):
		if m % i == 0:
			break
	return i
print(f())


from collections import deque
(N, M) = list(map(int, input().split()))
a = deque()
b = deque()
for i in range(1, int(M ** (1 / 2)) + 1):
	if M % i == 0:
		a.appendleft(i)
		b.append(M // i)
b.extend(a)
for i in b:
	m = M // i
	if m >= N:
		print(i)
		break


import math
(n, m) = map(int, input().split())
fact = []
ans = 1
MAX = int(math.sqrt(m)) + 1
for i in range(1, MAX):
	if m % i == 0:
		fact.append(i)
		if i != m // i:
			fact.append(m // i)
fact.sort()
for x in fact:
	if m < n * x:
		break
	ans = x
print(ans)


(n, m) = list(map(int, input().split()))

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
b = make_divisors(m)
a = m // n
ans = 0
for i in b:
	if i <= a:
		ans = i
print(ans)


(N, M) = map(int, input().split())
d = []
for i in range(1, int(M ** 0.5) + 1):
	if M % i == 0:
		d.append(i)
		d.append(M // i)
d.sort()
for i in range(1, len(d) + 1):
	if d[-i] <= M // N:
		print(d[-i])
		exit()


(n, m) = map(int, input().split())
ma = m // n
flag = 0
while flag == 0:
	if m % ma == 0:
		print(ma)
		flag = 1
	ma -= 1


import math
(n, m) = map(int, input().split())
X = 1
for i in range(1, 32000):
	if m % i == 0:
		if i * n <= m:
			X = max(X, i)
		if m // i * n <= m:
			X = max(X, m // i)
print(X)


(n, m) = map(int, input().split())
d = []
for i in range(1, int(m ** 0.5) + 1):
	if m % i == 0:
		e = m // i
		d.append(i)
		d.append(e)
ans = 0
for i in d:
	if m >= n * i:
		ans = max(ans, i)
print(ans)


import math
(n, m) = map(int, input().split())
for i in range(math.floor(m / n), 0, -1):
	if m % i == 0:
		ans = i
		break
print(ans)


(n, m) = map(int, input().split())
syou = m // n
amari = m % n
while True:
	if amari % syou == 0:
		print(syou)
		break
	else:
		amari += n
		syou -= 1


(N, M) = map(int, input().split())
for i in range(M // N, 0, -1):
	if M % i == 0:
		ans = i
		break
print(ans)


import bisect

def enum_devisors(n):
	divisors = set([])
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.add(i)
			divisors.add(n // i)
	return divisors
(n, m) = list(map(int, input().split()))
devisors = sorted(enum_devisors(m))
d = devisors[bisect.bisect_left(devisors, n)]
print(m // d)


(n, m) = list(map(int, input().split()))
divisors = []
for i in range(1, int(m ** 0.5) + 1):
	if m % i == 0:
		divisors.append(i)
		if i != m // i:
			divisors.append(m // i)
divisors.sort()
print([i for i in divisors if i <= m / n][-1])


(N, M) = map(int, input().split())
A = M // N
for i in range(A, 0, -1):
	Z = M % i
	if not Z or Z % i == 0:
		print(i)
		exit()


import sys
input = sys.stdin.readline
(N, M) = map(int, input().split())
g = M // N
for i in range(g):
	if M % (g - i) == 0:
		print(g - i)
		exit()
	if M % (N + i) == 0:
		print(M // (N + i))
		exit()


(n, m) = map(int, input().split())
maxnum = m // n
for i in range(maxnum, 0, -1):
	if m % i == 0:
		print(i)
		break


(N, M) = map(int, input().split())
mx = 0
for i in range(1, int(M ** 0.5) + 1):
	if M % i == 0:
		if M // i >= N:
			mx = max(mx, i)
		if i >= N:
			mx = max(mx, M // i)
print(mx)


from fractions import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
from sys import stdin
readline = stdin.readline

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

def readTuples():
	return tuple(map(int, readline().split()))

def I():
	return int(readline())
(n, m) = readInts()

def yaku(m):
	ans = []
	i = 1
	while i * i <= m:
		if m % i == 0:
			j = m // i
			ans.append(i)
			if j != i:
				ans.append(j)
		i += 1
	ans = sorted(ans)
	return ans
dic = yaku(m)
ans = 1
for k in dic:
	if k * n <= m:
		ans = max(ans, k)
print(ans)


(n, m) = (int(i) for i in input().split())
a = m // n
for i in range(a):
	x = a - i
	if m % x == 0:
		print(x)
		break


def main():
	(n, m) = map(int, input().split())
	start = m // n
	for i in range(start, 0, -1):
		if m % i == 0:
			print(i)
			break
main()


(N, M) = map(int, input().strip().split())
i = 1
while i <= M // N:
	if M % i == 0:
		maxg = i
		if M // i <= M // N:
			maxg = M // i
			break
	i += 1
print(maxg)


import bisect
(n, m) = map(int, input().split())
l = []
for i in range(1, int(m ** 0.5) + 1):
	if m % i == 0:
		l.extend([i, m // i])
l.sort()
print(l[bisect.bisect_right(l, m / n) - 1])


(n, m) = map(int, input().split())
ans = 1
for i in range(1, int(m ** 0.5) + 1):
	if m % i == 0:
		if i >= n:
			ans = max(ans, m // i)
		elif m // i >= n:
			ans = max(ans, i)
print(ans)


import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

def F():
	return float(input())

def SS():
	return input()

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

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

def LF():
	return [float(x) for x in input().split()]

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

def resolve():
	(N, M) = LI()
	M_div = []
	for i in range(1, int(M ** 0.5) + 1):
		if M % i == 0:
			M_div.append(i)
			M_div.append(M // i)
	ans = 1
	for i in M_div:
		if M // i >= N:
			ans = max(i, ans)
	print(ans)

def __starting_point():
	resolve()
__starting_point()


(n, m) = list(map(int, input().split()))
d = []
f = 1
while f * f < m + 1:
	if m % f == 0:
		d.append(f)
		d.append(m // f)
	f += 1
d.sort(reverse=True)
for i in d:
	if m - i * n >= 0 and (m - i * n) % i == 0:
		break
print(i)


import math
(n, m) = map(int, input().split())
kotae = 1
for i in range(1, int(math.sqrt(m)) + 1):
	if m % i == 0:
		if i * n <= m:
			kotae = max(kotae, i)
		if m // i * n <= m:
			kotae = max(kotae, m // i)
print(kotae)


(N, M) = map(int, input().split())
if M % N == 0:
	print(M // N)
else:
	a = M // N
	while a > 0:
		if (M - a * N) % a == 0:
			print(a)
			break
		else:
			a -= 1


(n, m) = map(int, input().split())
val = m // n
i = val
while i > 0:
	if m % i == 0:
		print(i)
		exit()
	i -= 1


(N, M) = map(int, input().split())
max_ = 1
for n in range(int(M / N) + 1, 0, -1):
	d = M - N * n
	if d >= 0 and d % n == 0:
		max_ = n
		break
print(max_)


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
(n, m) = list(map(int, input().split()))
if n % m == 0:
	print(int(n / m))
	return
else:
	lst = make_divisors(m)[::-1]
	for i in lst:
		if i == 1:
			print(i)
			return
		if m - i * (n - 1) > 0:
			if (m - i * (n - 1)) % i == 0:
				print(i)
				return
		else:
			continue


from math import sqrt
(N, M) = map(int, input().split())
ans = max((M // i if M // i <= M / N else i for i in range(1, int(sqrt(M)) + 1) if M % i == 0 and i <= M / N))
print(ans)


from fractions import gcd
from itertools import combinations, permutations, accumulate
from collections import deque, defaultdict, Counter
import decimal
import re
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7

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

def I():
	return int(input())
(n, m) = readInts()

def yaku(m):
	ans = []
	i = 1
	while i * i <= m:
		if m % i == 0:
			j = m // i
			ans.append(i)
			if j != i:
				ans.append(j)
		i += 1
	ans = sorted(ans)
	return ans
ya = yaku(m)
ans = -1
for a in ya:
	if a * n <= m:
		ans = a
	else:
		break
print(ans)


(N, M) = map(int, input().split())
d = []
for i in range(1, int(M ** 0.5 + 1)):
	if M % i == 0:
		d.append(i)
		d.append(M // i)
dd = list(set(d))
dd.sort()
for x in dd:
	if x >= N:
		print(M // x)
		break


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


import math
(N, M) = map(int, input().split())
a = M // N
ans = 0
for i in range(1, int(math.sqrt(M)) + 1):
	if M % i == 0:
		if i <= a and i > ans:
			ans = i
		if M // i <= a and M // i > ans:
			ans = M // i
print(ans)


(n, m) = map(int, input().split())
gcd = m // n
while n * gcd != m:
	gcd = m // n
	n = 1 + (m - 1) // gcd
print(gcd)


(n, m) = map(int, input().split())
div = m // n
INF = 10 ** 18
ans = -INF
for i in reversed(range(1, div + 1)):
	if m % i != 0:
		continue
	if ans < i:
		ans = i
		break
print(ans)


(n, m) = map(int, input().split())
pf = []
for i in range(1, int(m ** 0.5) + 1):
	if m % i == 0:
		pf.append(i)
		pf.append(m // i)
pf.sort(reverse=True)
ans = 100000000
for i in pf:
	if i >= n:
		ans = i
print(m // ans)


(n, m) = list(map(int, input().split()))
res = 1
num = int(m ** 0.5) + 1
for i in range(1, num):
	if m % i != 0:
		continue
	j = m // i
	if i >= n:
		res = max(j, res)
	if j >= n:
		res = max(i, res)
print(res)


(n, m) = map(int, input().split())
s = {1, m}
for i in range(2, int(m ** 0.5) + 1):
	if m % i < 1:
		s |= {i, m // i}
for i in sorted(s):
	if i * n > m:
		break
	a = i
print(a)


(n, m) = map(int, input().split())

def yakusuu(n, m):
	for i in range(int(m / n), 0, -1):
		if m % i == 0:
			print(i)
			break
yakusuu(n, m)


(N, M) = map(int, input().split())
gcd = M // N
while gcd * N != M:
	gcd = M // N
	N = 1 + (M - 1) // gcd
print(gcd)


(N, M) = map(int, input().split())
x = M // N
max = 1
for i in range(x, 0, -1):
	mod = M - (N - 1) * i
	if mod % i == 0:
		max = i
		break
print(max)


(N, M) = list(map(int, input().split()))
ans = 1
if N == 1:
	print(M)
else:
	for n in range(2, int(M ** 0.5) + 1):
		if M % n == 0 and M / N >= n:
			ans = max(ans, n)
			if M // n * N <= M:
				ans = max(ans, M // n)
	print(ans)


(N, M) = map(int, input().split())
div = 1
for i in range(2, M // N + 1)[::-1]:
	if M % i == 0:
		div = i
		break
print(div)


(n, m) = map(int, input().split())
li = []
for i in range(int(m ** 0.5) + 1, 0, -1):
	if i == int(m ** 0.5) + 1 and (i - 1) ** 2 == m:
		continue
	if m % i == 0:
		li.append(i)
		li.append(m // i)
li.sort(reverse=True)
for i in li:
	if n <= m // i:
		print(i)
		break


(n, m) = map(int, input().split())
print(next((v for v in range(m // n, -1, -1) if m % v == 0)))


(N, M) = map(int, input().split())
for g in range(M // N, 0, -1):
	if (M - (N - 1) * g) % g == 0:
		break
print(g)


(N, M) = [int(str) for str in input().strip().split()]
for i in range(M // N, 0, -1):
	if M % i == 0:
		print(i)
		exit()
print(1)


(k, s) = list(map(int, input().split()))
p = s
factors = {}
while p > 1:
	f = False
	for i in range(2, int(p ** 0.5) + 1):
		if p % i == 0:
			if i in factors:
				factors[i] += 1
			else:
				factors[i] = 1
			p //= i
			f = True
			break
	if not f:
		if p in factors:
			factors[p] += 1
		else:
			factors[p] = 1
		break
if len(factors) == 0:
	print(1)
else:
	primes = list(factors.keys())
	exp = [0] * len(primes)
	upper = s / k
	ans = 1
	while exp[0] <= factors[primes[0]]:
		num = 1
		for i in range(len(primes)):
			num *= pow(primes[i], exp[i])
		if num == upper:
			ans = num
			break
		elif num < upper:
			ans = max(ans, num)
		index = len(primes) - 1
		done = False
		while not done:
			exp[index] += 1
			if exp[index] > factors[primes[index]]:
				if index == 0:
					break
				else:
					exp[index] = 0
					index -= 1
			else:
				done = True
	print(ans)


(n, m) = map(int, input().split())

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
numbers = make_divisors(m)
for i in range(len(numbers)):
	if numbers[i] <= m / n:
		print(numbers[i])
		break


import math

def main():
	(N, M) = [int(a) for a in input().split(' ')]
	divM = []
	for i in range(1, int(math.sqrt(M)) + 1):
		if M % i == 0:
			divM += [i, M // i]
	divM.sort()
	divM = list(filter(lambda m: m >= N, divM))
	print(M // divM[0])
main()


import math
(N, M) = map(int, input().split())
if N == 1:
	print(M)
else:
	d = max((d for d in range(1, math.ceil(M / (N - 1))) if M % d == 0))
	print(d)


(N, M) = map(int, input().split())
work = M // N
while work > 0:
	if M % work == 0:
		print(work)
		exit(0)
	work -= 1


def divisor(x):
	from math import floor
	re = []
	_x = floor(x ** 0.5)
	for i in range(1, _x + 1):
		if x % i == 0:
			re.append(i)
			if x // i != i:
				re.append(x // i)
	re.sort()
	return re

def solve(N, M):
	div = divisor(M)
	div.sort()
	ans = 0
	for d in div:
		if M // d >= N:
			ans = d
	print(ans)

def __starting_point():
	(N, M) = list(map(int, input().split()))
	solve(N, M)
__starting_point()


(N, M) = map(int, input().split())
a = M // N
for i in range(a, 0, -1):
	if M % i == 0:
		print(i)
		exit()


(n, m) = map(int, input().split())

def func(n, num):
	if num == 1:
		return 1
	else:
		for i in range(num // n, 0, -1):
			if num % i == 0:
				return i
print(func(n, m))


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]
(N, M) = list(map(int, input().split()))
divisors = make_divisors(M)
ans = 0
for d in divisors:
	if N * d <= M:
		ans = d
print(ans)


import math
(N, M) = map(int, input().split())
for i in range(M // N + 1, 0, -1):
	if M % i == 0:
		if M // i >= N:
			print(i)
			exit()


(n, m) = map(int, input().split())
for i in range(m // n + 1)[::-1]:
	if m % i < 1:
		print(i)
		exit()


import math
(N, M) = map(int, input().split())
A = M // N
L = []
for i in range(1, int(math.sqrt(M)) + 1):
	if M % i == 0 and i <= A:
		L.append(i)
		if M // i <= A:
			L.append(M // i)
print(max(L))


(n, m) = map(int, input().split())
l = m // n

def x():
	for i in range(l + 1)[::-1]:
		if m % i == 0:
			return i
print(x())


(n, m) = map(int, input().split())
for i in range(2, m):
	if i * i > m:
		print(1)
		exit()
	if m % i == 0:
		break
for i in range(n, m + 1):
	if m % i == 0:
		print(m // i)
		exit()


(n, m) = map(int, input().split())
t = int(m / n)
while True:
	if m % t == 0:
		if t * n <= m:
			print(t)
			exit()
		else:
			t -= 1
	else:
		t -= 1


from bisect import bisect_right

def make_divisers(n):
	upper_result = []
	lower_result = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			lower_result.append(i)
			ii = n // i
			if ii != i:
				upper_result.append(ii)
	return lower_result + upper_result[::-1]

def main():
	(N, M) = map(int, input().split())
	divisers = make_divisers(M)
	idx = bisect_right(divisers, M / N) - 1
	print(divisers[idx])

def __starting_point():
	main()
__starting_point()


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


(N, M) = map(int, input().split())
yakusuu = []
for i in range(1, int(M ** 0.5) + 1):
	if M % i == 0:
		yakusuu.append(i)
		yakusuu.append(M // i)
print(max([a for a in yakusuu if a * N <= M]))


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


(n, m) = map(int, input().split())
ans = 0
for i in range(1, int(m ** 0.5) + 1):
	if m % i > 0:
		continue
	a = i
	b = m // i
	if a * n <= m:
		ans = max(ans, a)
	if b * n <= m:
		ans = max(ans, b)
print(ans)


(n, m) = map(int, input().split())
l = []
for i in range(1, int(m ** (1 / 2)) + 1):
	if m % i == 0:
		l.append(i)
		l.append(m // i)
l.sort()
l = l[::-1]
for i in l:
	if m // n >= i:
		print(i)
		break


(n, m) = list(map(int, input().split()))
d = m // n + 1
for x in range(d)[::-1]:
	if m % x == 0:
		break
print(x)


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


import bisect
(N, M) = map(int, input().split())
d = []
for i in range(1, int(M ** 0.5) + 2):
	if M % i == 0:
		d.append(i)
		d.append(M // i)
d.sort()
ind = bisect.bisect_right(d, M // N)
print(d[ind - 1])


(n, m) = map(int, input().split())
ans = m // n
while ans > 0:
	if m % ans == 0:
		if m // ans >= n:
			break
	else:
		ans -= 1
print(ans)


(N, M) = map(int, input().split())

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]
d = make_divisors(M)
d = list(filter(lambda x: x <= M / N, d))
print(d[-1])


(N, M) = map(int, input().split())
d = set()
k = 1
while k * k <= M:
	if M % k == 0:
		d.add(k)
		d.add(M // k)
	k += 1
ans = 1
for n in d:
	if n >= N:
		ans = max(ans, M // n)
print(ans)


import math
(N, M) = map(int, input().split())
max = 1
for i in range(1, int(math.sqrt(M)) + 2):
	if M % i == 0 and i >= N:
		max = int(M / i)
		break
	if M % i == 0 and M / i >= N:
		max = i
print(max)


def divisor(n):
	i = 1
	res = []
	while i * i <= n:
		if n % i == 0:
			res.append(i)
			if n // i not in res:
				res.append(n // i)
		i += 1
	res.sort()
	return res

def main():
	(n, m) = map(int, input().split())
	md = divisor(m)
	ans = 0
	for i in md:
		if (m - n * i) % i == 0 and m - n * i >= 0:
			ans = i
		else:
			break
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split())
x = m // n

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]
y = make_divisors(m)
res = 1
for i in y:
	if i <= x:
		res = i
print(res)


(N, M) = map(int, input().split())
P = []
A = round(M ** 0.5) + 2
for i in range(1, A):
	if M % i == 0:
		P.append(i)
		P.append(M // i)
P.sort()
B = M // N
ans = now = 1
for p in P:
	now = p
	if now <= B:
		ans = now
print(ans)


import sys
(n, m) = map(int, input().split())
ans = 1
for i in range(m // n, 0, -1):
	rest = m - i * (n - 1)
	if rest % i == 0:
		print(i)
		sys.exit()


(iN, iM) = [int(_) for _ in input().split()]
if iM % iN == 0:
	print(iM // iN)
else:
	aRet = []
	for i in range(1, iM // iN + 1):
		if iM % i == 0:
			aRet.append(i)
	print(aRet[-1])


(n, m) = map(int, input().split())
gcd = m // n
while True:
	if m % gcd == 0:
		print(gcd)
		return
	gcd -= 1


import math
(N, M) = [int(i) for i in input().split()]
for i in range(math.ceil(M / N), 0, -1):
	if M % i == 0:
		print(i)
		break


(n, m) = map(int, input().split())
for i in range(n, 10 ** 8):
	if m % i == 0:
		print(m // i)
		exit()
print(1)


(n, m) = list(map(int, input().split()))
d = [i for i in range(1, int(m ** 0.5) + 1) if m % i == 0]
d.extend([m // i for i in d])
print(max([i for i in d if m // i >= n]))


from math import sqrt, floor
(N, M) = map(int, input().split())
ans = 1
for g in range(1, floor(sqrt(M)) + 1):
	if M % g == 0:
		x = M // g
		if x > floor(sqrt(M)) and g >= N:
			ans = x
			break
		if x >= N:
			ans = g
print(ans)


from bisect import bisect_left, bisect

def enum_div(n):
	ir = int(n ** 0.5) + 1
	ret = []
	for i in range(1, ir):
		if n % i == 0:
			ret.append(i)
			if (i != 1) & (i * i != n):
				ret.append(n // i)
	return ret
(n, m) = list(map(int, input().split()))
div = enum_div(m) + [m]
div.sort(reverse=True)
rd = [0] * len(div)
for i in range(len(div)):
	rd[i] = m // div[i]
mm = bisect_left(rd, n)
print(div[mm])


(n, m) = list(map(int, input().split()))
yakusuu = []
for i in range(1, int(m ** 0.5) + 1):
	if m % i == 0:
		yakusuu.append(m // i)
		if m // i == i:
			continue
		yakusuu.append(i)
ans = 0
for y in yakusuu:
	if y < n:
		continue
	if m % y == 0:
		ans = max(ans, m // y)
print(ans)


(N, M) = map(int, input().split())

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
div_ls = make_divisors(M)
ans = 1
for div in div_ls:
	if div * N <= M:
		ans = max(ans, div)
print(ans)


(n, m) = map(int, input().split())
x = 1
s = 1
while x ** 2 <= m:
	(a, b) = divmod(m, x)
	if a >= n and b == 0:
		s = max(x, s)
	if x >= n and b == 0:
		s = max(a, s)
	x += 1
print(s)


import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def divisors(n):
	lower = []
	upper = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			lower.append(i)
			if i != n // i:
				upper.append(n // i)
	lower.extend(reversed(upper))
	return lower

def main():
	(N, M) = list(map(int, readline().split()))
	divisor = divisors(M)
	for d in reversed(divisor):
		if M // d >= N:
			ans = d
			break
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


(N, M) = map(int, input().split())
for base in range(1, M // N + 1)[::-1]:
	if M % base != 0:
		continue
	print(base)
	break


(N, M) = map(int, input().split())
print(next((d for d in reversed(range(M // N + 1)) if M % d == 0)))


(N, M) = list(map(int, input().split()))
ans = 1
for i in range(1, int(M ** 0.5) + 1):
	if M % i == 0:
		j = M // i
		if i >= N:
			ans = max(ans, j)
		if j >= N:
			ans = max(ans, i)
print(ans)


(n, m) = map(int, input().split())
K = m // n
ans = 0
i = 1
while i <= K:
	if m % i == 0:
		if m // i <= K:
			ans = m // i
			break
		ans = i
		K = min(m // n, m // i)
	i += 1
print(ans)


(n, m) = map(int, input().split())
ans = 1
for i in range(1, int(m ** 0.5) + 1):
	if m % i:
		continue
	if m // i >= n and i > ans:
		ans = i
	if i >= n and m // i >= ans:
		ans = m // i
print(ans)


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


def calc():
	(N, M) = map(int, input().split())
	for gcd in range(M // N, 0, -1):
		if M % gcd == 0:
			break
	return gcd
print(calc())


(N, M) = map(int, input().split())
ans = M // N
while True:
	if (M - (N - 1) * ans) % ans == 0:
		break
	ans -= 1
print(ans)


def prime(n):
	l = [[], []]
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if i * i == n:
				l[0].append(i)
			else:
				l[0].append(i)
				l[1].append(n // i)
	return l[0] + l[1][::-1]
(n, m) = map(int, input().split())
x = 0
for i in prime(m):
	if i <= m // n:
		x = i
print(x)


(N, M) = map(int, input().split())

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]
l = make_divisors(M)
threshold = M / N
for (i, d) in enumerate(l):
	if threshold < d:
		print(l[i - 1])
		return
print(M)


(n, m) = map(int, input().split())
a = m // n
di = []
for i in range(1, min(a + 1, int(m ** 0.5) + 1)):
	if m % i == 0:
		di.append(i)
		if i != m // i and a >= m // i:
			di.append(m // i)
di.sort()
print(di[-1])


(n, m) = map(int, input().split())
st = m // n
for i in range(st, 0, -1):
	mod = m - n * i
	if mod % i == 0:
		print(i)
		break


(N, M) = map(int, input().split())
divs = []
for i in range(1, int(M ** 0.5) + 1):
	if M % i == 0:
		divs.append(i)
		divs.append(M // i)
print(max([d for d in divs if d * N <= M]))


import math
(n, m) = map(int, input().split())
ans = list()
for i in range(1, int(math.sqrt(m)) + 1):
	if m % i == 0:
		ans.append(i)
		ans.append(m // i)
ans.sort(reverse=True)
for x in ans:
	if x <= m // n:
		print(x)
		break


import math
(n, m) = list(map(int, input().split()))
num = int(math.sqrt(m))
ans = 1
for i in range(1, num + 2):
	if m % i == 0 and i >= n:
		ans = max(ans, m // i)
		break
	if m % i == 0 and m // i >= n:
		ans = max(ans, i)
print(ans)


(N, M) = map(int, input().split())
L = []
ans = 0
for i in range(1, int(M ** (1 / 2) + 1)):
	if M % i == 0:
		if i >= N:
			ans = max(ans, M // i)
		if M // i >= N:
			ans = max(ans, i)
print(ans)


from math import sqrt

def divisors(n):
	divisors = []
	for i in range(1, int(sqrt(n)) + 1):
		(q, r) = divmod(n, i)
		if r == 0:
			divisors.append(i)
			if i != q:
				divisors.append(q)
	divisors.sort()
	return divisors
(n, m) = map(int, input().split())
ans = 1
for a in divisors(m)[1:]:
	if a * n <= m:
		ans = a
print(ans)


(N, M) = map(int, input().split())

def enum_div(N):
	ret = []
	for i in range(1, int(N ** 0.5) + 1):
		if N % i == 0:
			ret.append(i)
			if i ** 2 != N:
				ret.append(N // i)
		i += 1
	return ret
ans = 0
for i in enum_div(M):
	if i >= N:
		ans = max(ans, M // i)
print(int(ans))


import bisect
(N, M) = list(map(int, input().split()))
divd = []
i = 1
while i * i <= M:
	if M % i == 0:
		divd.append(i)
		if i != M // i:
			divd.append(M // i)
	i += 1
divd.sort()
k = bisect.bisect_left(divd, N)
print(M // divd[k])


import sys

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]
(N, M) = list(map(int, input().split()))
i = 1
ans = 1
d_ls = make_divisors(M)
for i in d_ls:
	if i * N > M:
		break
	if (M - N * i) % i == 0:
		ans = i
	i += 1
print(ans)


(N, M) = map(int, input().split())
if M % N == 0:
	print(M // N)
	quit()
for i in range(M // N + 1):
	if M % (M // N - i) == 0:
		print(M // N - i)
		quit()


(N, M) = map(int, input().split())
g = 1
for i in range(1, int(M ** (1 / 2)) + 1):
	if M % i == 0:
		if i >= N:
			g = M / i
			print(int(g))
			exit()
		elif i <= M / N:
			g = i
print(int(g))


(N, M) = map(int, input().split())
X = M // N
for x in range(X, 1, -1):
	r = M - x * (N - 1)
	if r % x == 0:
		print(x)
		exit()
print(1)


(N, M) = map(int, input().split())

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
for i in reversed(range(1, M // N + 1)):
	if M % i == 0:
		print(i)
		break


(N, M) = map(int, input().split())

def enum_div(N):
	ret = []
	i = 1
	while True:
		if i ** 2 > N:
			break
		if N % i == 0:
			ret.append(i)
			if i ** 2 != N:
				ret.append(N / i)
		i += 1
	return ret
ans = 0
for i in enum_div(M):
	if i >= N:
		ans = max(ans, M / i)
print(int(ans))


def LI():
	return list(map(int, input().split()))
(N, M) = LI()
x = M // N
for i in range(x, 0, -1):
	if M % i != 0:
		continue
	ans = i
	break
print(ans)


from math import ceil, floor, factorial, gcd, sqrt, log2, cos, sin, tan, acos, asin, atan, degrees, radians, pi, inf
from itertools import accumulate, groupby, permutations, combinations, product, combinations_with_replacement
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)

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

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

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

def LIST():
	return list(MAP())

def divisor(n):
	i = 1
	table = []
	while i * i <= n:
		if n % i == 0:
			table.append(i)
			table.append(n // i)
		i += 1
	table = list(set(table))
	return table
(n, m) = MAP()
a = sorted(divisor(m))
print(m // a[bisect_left(a, n)])


def solve():
	(N, M) = map(int, input().split())
	for i in range(M // N, 0, -1):
		if not M % i:
			return str(i)
print(solve())


(n, m) = map(int, input().split())
l = [1]
k = m // n
if n == 1:
	print(m)
	exit()
for i in range(2, int(m ** 0.5) + 1):
	if m % i == 0:
		if i <= k:
			l.append(i)
		if m // i <= k:
			l.append(m // i)
print(max(l))


(n, m) = list(map(int, input().split()))

def solve():
	for i in range(m // n, 0, -1):
		if m % i == 0:
			if m // i >= n:
				print(i)
				break
solve()


(n, m) = list(map(int, input().split()))
ans = m // n
while m % ans != 0:
	ans -= 1
print(ans)


(N, M) = map(int, input().split())
ans = 1
i = 1
while i * i <= M:
	if M % i == 0 and M // N >= i:
		ans = max(ans, i)
		if M // i * N <= M:
			ans = max(ans, M // i)
	i += 1
print(ans)


(N, M) = map(int, input().split())
if N == 1:
	print(M)
else:
	d = max((d for d in range(1, M // N + 1) if M % d == 0))
	print(d)


from math import sqrt
(N, M) = map(int, input().split())
cand = []
for i in range(1, int(sqrt(M)) + 1):
	if M % i == 0:
		cand.append(i)
		u = M // i
		if u != i:
			cand.append(u)
cand.sort()
ans = 1
for j in cand:
	if N * j <= M:
		ans = max(ans, j)
print(ans)


(N, M) = list(map(int, input().split()))

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]
div_list = make_divisors(M)
div_list = div_list[::-1]
for div in div_list:
	if N * div <= M:
		print(div)
		return


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


(N, M) = map(int, input().split())
a = M // N
x = 1
for i in range(1, a + 1):
	if M % i == 0:
		x = i
		if M // i > i and M // i <= a:
			x = M // i
			break
print(x)


(n, m) = map(int, input().split())
ans = 1
ps = []
for i in range(1, int(m ** (1 / 2)) + 1):
	if m % i:
		continue
	if n * i <= m:
		ans = max(i, ans)
	if n * (m // i) <= m:
		ans = max(ans, m // i)
print(ans)


def divisor(n):
	cd = []
	i = 1
	while i * i <= n:
		if n % i == 0:
			cd.append(i)
			if i != n // i:
				cd.append(n // i)
		i += 1
	return cd
(N, M) = map(int, input().split())
cd = divisor(M)
cd.sort(reverse=True)
for c in cd:
	if M // c >= N:
		print(c)
		break


[print(max([i for j in [[i, a[1] // i] for i in range(1, int(a[1] ** 0.5) + 1) if a[1] % i == 0] for i in j if a[1] // i >= a[0]])) for a in [list(map(int, input().split()))]]


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

def main():
	(n, m) = map(int, input().split())
	md = divisor(m)
	ans = 0
	for i in md:
		if i * n <= m:
			print(i)
			return

def __starting_point():
	main()
__starting_point()


from collections import defaultdict
(n, m) = list(map(int, input().split()))
ans = 0
i = 1
while i * i <= m:
	if m % i == 0:
		(a, b) = (i, m // i)
		if b >= n:
			ans = max(ans, a)
		if a >= n:
			ans = max(ans, b)
	i += 1
print(ans)


(N, M) = list(map(int, input().split()))

def primes(n):
	d = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			d.append(i)
			if n // i != i:
				d.append(n // i)
	d.sort()
	return d
d = primes(M)
for i in d[::-1]:
	if M // i >= N:
		ans = i
		break
print(ans)


def inpl():
	return list(map(int, input().split()))
(N, M) = inpl()
n = M // N
while n > 0:
	if M % n == 0:
		print(n)
		break
	else:
		n -= 1


(N, M) = map(int, input().split())
A = []
for i in range(1, M + 1):
	if i * i > M:
		break
	if M % i == 0:
		A.append(i)
		A.append(M // i)
A.sort()
for a in A:
	if a >= N:
		print(M // a)
		break


(n, m) = map(int, input().split())
p = 1
for i in range(1, int(m ** 0.5) + 1):
	if m % i == 0:
		if m // i >= n:
			if i >= n:
				p = max(i, m // i, p)
			else:
				p = max(p, i)
print(p)


(N, M) = map(int, input().split())
a = 1
for i in range(1, 4 * 10000):
	if M % i:
		continue
	if M // i >= N and i > a:
		a = i
	if i >= N and M // i > a:
		a = M // i
print(a)


def run():
	(N, M) = (int(x) for x in input().split())
	i = 2
	result = 1
	for i in range(M // N, 0, -1):
		if M % i == 0:
			print(i)
			break
run()


(N, M) = map(int, input().split())
output = 1
for i in range(M // N, 0, -1):
	if M % i == 0 and output < i:
		output = i
		break
print(output)


def main():
	import sys

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

	def divisor(m):
		arr = [1, m]
		i = 2
		while i * i <= m:
			if m % i == 0:
				arr.append(i)
				if m // i != i:
					arr.append(m // i)
			i += 1
		arr.sort()
		return arr
	(n, m) = map(int, input().split())
	a = divisor(m)
	for x in a:
		if x >= n:
			print(m // x)
			return

def __starting_point():
	main()
__starting_point()


(n, m) = list(map(int, input().split()))
i = n
while i * i <= m:
	if m % i == 0:
		print(m // i)
		exit()
	i += 1
j = m // i
while j > 0:
	if m % j == 0:
		print(j)
		exit()
	j -= 1


(N, M) = map(int, input().split())
if M % N == 0:
	print(M // N)
	exit()
A = []
for i in range(1, M // N + 1):
	if M % i == 0:
		A.append(i)
print(A[-1])


(N, M) = map(int, input().split())
ceil = M // N
for i in range(1, ceil + 1)[::-1]:
	tmp = M - i * (N - 1)
	if tmp > 0 and tmp % i == 0:
		print(i)
		break


(N, M) = map(int, input().split())

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
ans = 1
for i in make_divisors(M):
	work1 = i * N
	work2 = M - work1
	if work2 >= 0 and work2 % i == 0:
		ans = max(i, ans)
print(ans)


(n, m) = map(int, input().split())
L = []
x = m / n
for i in range(1, min(int(x) + 1, int(m ** 0.5) + 1)):
	if m % i == 0:
		if i <= x:
			L.append(i)
		if m // i <= x:
			L.append(m // i)
print(max(L))


(n, m) = [int(_) for _ in input().split(' ')]
ds = [i for i in range(1, int(m ** 0.5) + 1) if m % i == 0]
ds.extend([m // i for i in ds])
print(max([i for i in ds if i <= m // n]))


(N, M) = map(int, input().split())
d = []
for i in range(1, int(M ** 0.5) + 1):
	if M % i == 0:
		d.append(i)
		if i ** 2 != M:
			d.append(M // i)
d.sort(reverse=True)
for i in d:
	if i * N <= M:
		print(i)
		exit()


def enum_divisors(n):
	res = []
	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
(N, M) = list(map(int, input().split()))
divs = sorted(enum_divisors(M), reverse=True)
ans = max((d for d in divs if M // d >= N))
print(ans)


(N, M) = list(map(int, input().split()))
import math
G = []
for i in range(1, int(math.sqrt(M)) + 2 + 1):
	if M % i == 0:
		cd = M // i
		G.append(cd)
		G.append(i)
G.sort(reverse=True)
for g in G:
	n = M // g
	if n >= N:
		print(g)
		return


(N, M) = [int(i) for i in input().split()]
l = []
for i in range(1, int(M ** 0.5 + 2)):
	if M % i == 0:
		if M / i >= N:
			l.append(i)
		if i >= N:
			l.append(M / i)
print(int(max(l)))


(N, M) = map(int, input().split())
base = M // N
li = []
for i in range(1, int(pow(M, 1 / 2)) + 1):
	if i <= base and M % i == 0:
		li.append(i)
	if M % i == 0 and M // i <= base:
		li.append(M // i)
print(max(li))


from sys import stdin
nii = lambda : map(int, stdin.readline().split())
lnii = lambda : list(map(int, stdin.readline().split()))
(n, m) = nii()

def divisore(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
d = divisore(m)
for x in d:
	zan = m - x * n
	if zan >= 0 and zan % x == 0:
		print(x)
		return


(N, M) = map(int, input().split())
m = 1
ds = set()
while m * m <= M:
	if M % m == 0:
		ds.add(m)
		ds.add(M // m)
	m += 1
ans = 1
for d in ds:
	if d * N > M:
		continue
	ans = max(ans, d)
print(ans)


import sys

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]
(N, M) = map(int, input().split())
c = M // N
L = make_divisors(M)
L = list(reversed(L))
for i in range(len(L)):
	if L[i] <= c:
		print(L[i])
		return


(N, M) = map(int, input().split())
ave = M // N
amari = M % N
while True:
	if amari % ave == 0:
		ans = ave
		break
	else:
		ave -= 1
		amari = M % ave
print(ans)


(N, M) = list(map(int, input().split()))
a = M // N
for i in range(a, 0, -1):
	if M % i == 0:
		print(i)
		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)
	return divisors
(n, m) = map(int, input().split())
h = m // n
ans = 0
for d in make_divisors(m):
	if d <= h:
		ans = max(ans, d)
print(ans)


import math
(n, m) = map(int, input().split())
ans = 1
for i in range(1, math.ceil(math.sqrt(m))):
	if m % i == 0:
		if m >= n * i:
			ans = max(ans, i)
		j = m // i
		if m >= n * j:
			ans = max(ans, j)
print(ans)


import sys
input = sys.stdin.readline

def read():
	(N, M) = list(map(int, input().strip().split()))
	return (N, M)

def divisor(n):
	divisors = []
	i = 1
	while i * i <= n:
		if n % i == 0:
			divisors.append(i)
			if i * i != n:
				divisors.append(n // i)
		i += 1
	return list(sorted(divisors))

def solve(N, M):
	D = divisor(M)
	ans = 1
	for p in D:
		n = M // p
		if n >= N:
			ans = max(ans, p)
	return ans

def __starting_point():
	inputs = read()
	outputs = solve(*inputs)
	if outputs is not None:
		print('%s' % str(outputs))
__starting_point()


(n, m) = map(int, input().split())
k = m // n
ans = 1
i = 1
while i ** 2 <= m:
	if m % i == 0:
		j = m // i
		if j <= k:
			print(j)
			exit()
		if i <= k:
			ans = max(ans, i)
	i += 1
print(ans)


(n, m) = map(int, input().split())
temp = m // n
(i, ans) = (1, 1)
while i * i <= m:
	if m % i == 0:
		if ans < i <= temp:
			ans = i
		if ans < m // i <= temp:
			ans = m // i
	i += 1
print(ans)


(n, m) = list(map(int, input().split()))
ls = []
for i in range(1, int(m ** (1 / 2)) + 1):
	if m % i == 0:
		ls.append(i)
		ls.append(m // i)
ls = sorted(list(set(ls)), reverse=True)
for j in ls:
	if j * n <= m:
		print(j)
		break


(N, M) = map(int, input().split())

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]
A = make_divisors(M)
for i in range(len(A)):
	if A[i] >= N:
		print(A[-1 - i])
		return


(n, m) = list(map(int, input().split()))

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]
l = make_divisors(m)
l.reverse()
for x in l:
	if m // x >= n:
		print(x)
		break


(N, M) = map(int, input().split())
D = []
for i in range(1, int(M ** 0.5 + 1)):
	if M % i == 0:
		D.append(i)
		D.append(M // i)
D.sort()
for j in D:
	if j >= N:
		print(M // j)
		exit()


(n, m) = map(int, input().split())
i = 1
x = []
while i * i <= m:
	if m % i == 0:
		x.append(i)
		x.append(m // i)
	i += 1
x.sort()
for xi in x:
	if xi >= n:
		print(m // xi)
		break


(N, M) = list(map(int, input().split(' ')))

def solv(N, M):
	d = M // N
	for i in range(d + 1)[::-1]:
		if M % i == 0:
			return i
print(solv(N, M))


(n, m) = map(int, input().split())
ans = 0
import math
for i in range(1, int(math.sqrt(m)) + 1):
	if m % i != 0:
		continue
	i2 = m // i
	if i * n <= m:
		ans = max(ans, i)
	if i2 * n <= m:
		ans = max(ans, i2)
print(ans)


(n, m) = map(int, input().split())
an = m // n
while an * n != m:
	an = m // n
	n = 1 + (m - 1) // an
print(an)


(N, M) = list(map(int, input().split()))
(s, r) = divmod(M, N)
ans = 1
for i in range(s, 0, -1):
	if M % i == 0:
		print(i)
		break


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


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


(N, M) = map(int, input().split())

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 sorted(lower_divisors + upper_divisors[::-1], reverse=True)
divisors = make_divisors(M)
for d in divisors:
	tmp = M // d
	if tmp >= N:
		print(d)
		break


(N, M) = map(int, input().split())
L = []
for i in range(1, int(M ** 0.5) + 1):
	if M % i == 0:
		L.append(i)
		L.append(int(M / i))
L1 = [i for i in L if M / i >= N]
print(max(L1))


def resolve():

	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
	(N, M) = list(map(int, input().split()))
	div = make_divisors(M)
	for d in div:
		if d <= M // N:
			print(d)
			break

def __starting_point():
	resolve()
__starting_point()


(N, M) = map(int, input().split())
i = 1
lis = []
while M // i >= N and i <= M ** 0.5:
	if M % i == 0:
		lis.append(i)
	i += 1
for l in lis[::-1]:
	ans = M // l
	if M // ans >= N:
		lis.append(ans)
print(lis[-1])


import sys
import math
(N, M) = map(int, sys.stdin.readline().split())
ans = 0
for i in range(1, int(M ** 0.5) + 1):
	if M % i == 0:
		j = M // i
		r1 = j // N
		r2 = j % N
		ans = max(ans, min(r1, math.gcd(r1, r2)) * i)
		r1 = i // N
		r2 = i % N
		ans = max(ans, min(r1, math.gcd(r1, r2)) * j)
print(ans)


(n, m) = map(int, input().split())
max_cnd = m // n
for i in range(max_cnd):
	if m % (max_cnd - i) == 0:
		print(max_cnd - i)
		exit()


(n, m) = map(int, input().split())
a = 0
for i in range(1, int(m ** 0.5) + 1):
	if m % i == 0 and m // i >= n:
		a = max(a, i)
	if m % i == 0 and i >= n:
		a = max(a, m // i)
print(a)


from itertools import *
(n, m) = map(int, input().split())
M = m
a = [1]
for i in range(2, int(m ** 0.5) + 1):
	while m % i == 0:
		m //= i
		a += [i]
if m != 1:
	a += [m]
ans = 1
for i in range(len(a)):
	for b in combinations_with_replacement(set(a), i):
		c = 1
		for j in b:
			c *= j
		if c >= n and M % c == 0:
			ans = max(ans, M // c)
print(ans)


(n, m) = list(map(int, input().split()))
ans = 0
for i in range(1, int(m ** 0.5) + 1):
	if m % i == 0 and i <= m / n:
		if m // i <= m / n:
			ans = m // i
			break
		else:
			ans = i
print(ans)


from math import sqrt

def f(x):
	divisors = [[], []]
	for i in range(1, int(sqrt(x)) + 1):
		if x % i == 0:
			divisors[0].append(i)
			if i * i != x:
				divisors[1].append(x // i)
	return divisors[0] + divisors[1][::-1]
(n, m) = map(int, input().split())
for i in f(m):
	if n <= i:
		print(m // i)
		return


(n, m) = list(map(int, input().split()))
i = 1
ans = 0
while i * i <= m:
	if m % i == 0:
		if n <= m / i:
			ans = max(ans, i)
		if n <= i:
			ans = max(ans, m // i)
	i += 1
print(ans)


(n, m) = map(int, input().split())
max_num = int(m / n)
ans = -1
for i in reversed(range(max_num + 1)):
	if m % i == 0:
		ans = i
		break
print(ans)


import sys
(n, m) = map(int, input().split())
for div in reversed(range(1, 1 + m // n)):
	if m % div == 0:
		print(div)
		sys.exit()


import sys, math
from functools import lru_cache
from collections import deque
from bisect import bisect_left
sys.setrecursionlimit(10 ** 9)

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

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

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

def i2(n):
	tmp = [list(mi()) for i in range(n)]
	return [list(i) for i in zip(*tmp)]

def main():
	(N, M) = mi()
	d = []
	i = 1
	while i * i <= M:
		if M % i == 0:
			d.append(i)
			d.append(M // i)
		i += 1
	d.sort()
	for v in d:
		if v <= M // N:
			ans = v
		else:
			break
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split())
g = m // n
while 1:
	if m % g == 0:
		break
	g -= 1
print(g)


(n, m) = map(int, input().split())
p = m // n
while m % p != 0:
	p -= 1
print(p)


(x, y) = map(int, input().split())
a = 1
k = pow(y, 0.5)
for i in range(1, int(k) + 1):
	if y % i == 0:
		if i * x <= y:
			a = max(a, i)
		if y // i * x <= y:
			a = max(a, y // i)
print(a)


(N, M) = map(int, input().split())
ls = []
for i in range(1, M + 1):
	if M % i == 0:
		j = M // i
		if i <= M // N:
			ls += [i]
		if j <= M // N:
			ls += [j]
	if M ** 0.5 < i:
		break
print(max(ls))


import copy
import random
import bisect
import fractions
import math
import sys
import collections
from decimal import Decimal
mod = 10 ** 9 + 7
sys.setrecursionlimit(mod)
d = collections.deque()

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

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

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]
divs = make_divisors(M)
ans = -1
for (i, divisior) in enumerate(divs):
	if divisior > M // N:
		break
	else:
		ans = divisior
print(ans)


import sys
input = sys.stdin.readline

def calc_divisors(n):
	divisors_a = []
	divisors_b = []
	for d in range(1, int(n ** 0.5) + 1):
		if n % d == 0:
			divisors_a.append(d)
			if n // d != d:
				divisors_b.append(n // d)
	divisors = divisors_a + divisors_b[::-1]
	return divisors

def main():
	(N, M) = list(map(int, input().split()))
	divisors = calc_divisors(M)
	ans = 0
	for divisor in divisors:
		if M // divisor >= N:
			ans = max(ans, divisor)
	print(ans)

def __starting_point():
	main()
__starting_point()


import math
(N, M) = map(int, input().split())
l = []
for i in range(1, int(math.sqrt(M)) + 1):
	if M % i == 0:
		l.append(i)
		if i != M // i:
			l.append(M // i)
l.sort(reverse=True)
for n in l:
	if n * N <= M:
		ans = n
		break
print(ans)


(n, m) = map(int, input().split())
a = 1
b = 0
while b == 0:
	for i in range(int(m ** 0.5) * 10, 1, -1):
		if m % i == 0 and m >= i * n:
			a *= i
			m = m // i
			break
	else:
		b = 1
print(a)


(N, M) = map(int, input().split())
if M % N == 0:
	print(M // N)
else:
	ans = 1
	for n in range(1, M // N + 1):
		res = M - n * N
		if res % n == 0:
			ans = n
	print(ans)


(n, m) = list(map(int, input().split(' ')))
ds = [x for x in range(1, int(m ** 0.5) + 1) if m % x == 0]
ds = ds + [m // x for x in ds]
ds = [x for x in ds if x <= m // n]
print(max(ds))


(n, k) = map(int, input().split())
m = 1
for i in range(k // n + 1)[::-1]:
	if k % i == 0 and k // i >= n:
		m = i
		break
print(m)


(n, m) = map(int, input().split())
a = m // n
while True:
	if m / a == int(m / a):
		print(a)
		exit()
	a -= 1


import math
(n, m) = list(map(int, input().split()))
if n == 1:
	print(m)
	return
a = []
b = []
for i in range(1, math.ceil(math.sqrt(m))):
	if m % n == 0:
		print(m // n)
		return
	if m % i == 0:
		b.append(i)
		b.append(m // i)
for i in range(len(b)):
	if b[i] * n <= m:
		a.append(b[i])
if len(b) == 2:
	print(1)
else:
	print(max(a))