Problem:
 Score : 400 points    Problem Statement 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 1 3 14      Sample Output 1 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.       Sample Input 2 10 123      Sample Output 2 3       Sample Input 3 100000 1000000000      Sample Output 3 10000

Solution (Python):
def main():
    """
    input:
        1 <= N <= 10^5
        N <= M <= 10^9

        a1 + a2 + ... + aN = M
        1 <= ai

    output:
        数列の項の最大公約数の最大値
    """
    N, M = map(int, input().split())

    
    ans = editorial(N, M)
    print(ans)


def f(N, M):
    """
    最大公約数1:
        1が含まれる
        互いに素

    最大公約数2:
        すべて2の倍数

    N=M: すべて1
    M=奇数: 最大公約数は奇数
    まず1ずつ配る
        M -= N

    N,M: 0は偶数、1は奇数
    0 0: 配ってもMは偶数のまま
    0 1: 配ってもMは奇数のまま
         1余るので配る時に２回分配る、余りはどれかに割り当てて偶数にする
    1 0: 奇数回目の配るときには奇数、偶数回目のときは偶数
    1 1: 配ってもMは奇数のまま、01と同じパターン

    """
    if N == 1:
        return M

    if N == M or M < N * 2:
        return 1

    
    ans = 1
    d = 1
    M -= M
    while M >= N:
        
        M -= N
        d += 1

        
        if True:
            ans = d

    return ans


def editorial(N, M):
    """
    すべての項がK倍なら、最大公約数は最低でもKであり、それらの和であるMもKの倍数
    Mの約数は、M=A*B=B*A の対称性より
        最大 root(10^9) まで試せば良いのでTLEしない
    N=1,M=10^9のとき、最初の考えではTLEになる
    """
    ans = 1
    a_max = int(M ** 0.5)
    for a in range(1, a_max + 1):
        if M % a != 0:
            continue

        
        b = M // a

        
        
        
        if a * N <= M:
            ans = max(ans, a)
        if b * N <= M:
            ans = max(ans, b)

    return ans


if __name__ == '__main__':
    main()

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

Solution (Python):



def main():
    from math import sqrt

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

    
    
    for k in range(1, int(sqrt(m)) + 1):
        if m % k != 0:
            continue

        if k * n <= m:
            ans = max(ans, k)

        b = m // k

        if b * n <= m:
            ans = max(ans, b)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from math import sqrt
n, m = list(map(int, input().split()))
i = 1
lst = []
while i <= sqrt(m):
    if m % i == 0:
        j = m // i
        if i >= n:
            lst.append(i)
        if j >= n:
            lst.append(j)
    i += 1
print(m//min(lst))

Solution (Python):


import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


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


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


def read_float():
    return float(input())


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


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


def read_str_n():
    return list(map(str, input().split()))


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


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def fs(n):
    f = Counter()
    for i in range(2, math.ceil(math.sqrt(n)) + 1):
        if i > n:
            break
        while n % i == 0:
            f[i] += 1
            n /= i
    if int(n) != 1:
        f[int(n)] = 1
    return f

@mt
def slv(N, M):
    ans = 1
    for m in range(1, math.ceil(math.sqrt(M))+1):
        if M % m != 0:
            continue
        
        if  N*m <= M:
            ans = max(ans, m)
        if  N*(M//m) <= M:
            ans = max(ans, M//m)

    return ans


def main():
    N, M = read_int_n()
    print(slv(N, M))


if __name__ == '__main__':
    main()

Solution (Python):
import  math
N,M = map(int,input().split())

def f(M):
    l = []
    for i in range(1,int(math.sqrt(M))+1):
        if M%i==0:
            l.append(i)
    n = len(l)
    for i in range(n):
        j = l[n-1-i]
        if M/j!=j:
            l.append(M//j)
    return l

l = f(M)

for i in range(len(l)):
    n = l[-1-i]
    if M/n >= N:
        ans = n
        break
print(ans)

Solution (Python):
import math, operator
from collections import Counter
from itertools import chain, product, permutations, combinations
from functools import reduce, lru_cache
class PrimeUtils:
    @staticmethod
    def primes_sieve(n):
        sieve = [True] * (n + 1)
        for i in range(2, n + 1):
            if sieve[i]:
                for j in range(i + i, n + 1, i):
                    sieve[j] = False
        return [i for i, x in enumerate(sieve[2:], 2) if x]
    
    @classmethod
    def pfd(cls, n):
        rn = math.ceil(math.sqrt(n))
        primes = cls.primes_sieve(rn)

        factors = []
        cur = n
        for p in primes:
            while True:
                div, rem = divmod(cur, p)
                if rem == 0:
                    factors.append(p)
                    cur = div
                else:
                    break
        if cur != 1 or not factors:
            factors.append(cur)
        return factors
    
    @classmethod
    def aliquots(cls, n):
        pf = cls.pfd(n)
        pfc = Counter(pf)
        ppv = [[pow(p, i) for i in range(n+1)] for p,n in pfc.items()]
        return map(lambda x: reduce(operator.imul, x), product(*ppv))

N, M = map(int, input().split())
max_ans = M // N
print(max(filter(lambda a: a <= max_ans, PrimeUtils.aliquots(M))))

Solution (Python):
import itertools
import math
import copy

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

M2=copy.deepcopy(M)

A={}

a=int( math.sqrt(M) )+2

for i in range(2,a):
	while M%i==0:
		if i not in A:
			A[i]=1
		else:
			A[i]+=1
		M/=i
else:
	A[M]=1



B=[]

for x in A.values():
	B.append( range(x+1) )


L=list(itertools.product(*B))


Y=[]	
for x in L:
	t=1
	for i,j in zip(A,x):
		t*=i**j
	Y.append(t)


ans=0
for cd in Y:	
	if M2/cd>=N:
		ans=max(ans,cd)

print ans

Solution (Python):
import math, operator
from collections import Counter
from itertools import chain, product, permutations, combinations
from functools import reduce, lru_cache
class PrimeUtils:
    @staticmethod
    def primes_sieve(n):
        sieve = [True] * (n + 1)
        for i in range(2, n + 1):
            if sieve[i]:
                for j in range(i + i, n + 1, i):
                    sieve[j] = False
        return [i for i, x in enumerate(sieve[2:], 2) if x]
    @classmethod
    
    def pfd(cls, n):
        rn = math.ceil(math.sqrt(n))
        primes = cls.primes_sieve(rn)

        factors = []
        cur = n
        for p in primes:
            while True:
                div, rem = divmod(cur, p)
                if rem == 0:
                    factors.append(p)
                    cur = div
                else:
                    break
        if cur != 1 or not factors:
            factors.append(cur)
        return factors
    @classmethod
    
    def aliquots(cls, n):
        pf = cls.pfd(n)
        pfc = Counter(pf)
        ppv = [[pow(p, i) for i in range(n+1)] for p,n in pfc.items()]
        return map(lambda x: reduce(operator.imul, x), product(*ppv))

N, M = map(int, input().split())
print(M // min(filter(lambda a: N <= a, PrimeUtils.aliquots(M))))

Solution (Python):
import math, operator
from collections import Counter
from itertools import chain, product, permutations, combinations
from functools import reduce, lru_cache
class PrimeUtils:
    @staticmethod
    def primes_sieve(n):
        sieve = [True] * (n + 1)
        for i in range(2, n + 1):
            if sieve[i]:
                for j in range(i + i, n + 1, i):
                    sieve[j] = False
        return [i for i, x in enumerate(sieve[2:], 2) if x]
    @classmethod
    
    def pfd(cls, n):
        rn = math.ceil(math.sqrt(n))
        primes = cls.primes_sieve(rn)

        factors = []
        cur = n
        for p in primes:
            while True:
                div, rem = divmod(cur, p)
                if rem == 0:
                    factors.append(p)
                    cur = div
                else:
                    break
        if cur != 1 or not factors:
            factors.append(cur)
        return factors
    @classmethod
    
    def aliquots(cls, n):
        pf = cls.pfd(n)
        pfc = Counter(pf)
        ppv = [[pow(p, i) for i in range(n+1)] for p,n in pfc.items()]
        return map(lambda x: reduce(operator.imul, x), product(*ppv))

N, M = map(int, input().split())
for factor in sorted(PrimeUtils.aliquots(M)):
    if N <= factor:
        print(M // factor)
        break
else:
    print(1)

Solution (Python):
from math import sqrt

n, m = map(int, input().split())
l = []
for i in range(1, int(sqrt(m)) + 1):
	if m % i == 0:
		l.append(i)
		l.append(m // i)

ans = 1
for d in l:
	if d * n <= m:
		ans = max(ans, d)

print(ans)

Solution (Python):

def 解():
    iN,iM = [int(_) for _ in input().split()]
    iD = iM // iN
    if iM % iN == 0:
        print(iD)
    elif 2*iN > iM :
        print(1)
    else:
        aD = []
        iRtM = int(iM**0.5)
        if iRtM > iD:
            for i in range(iD,0,-1):
                if iM % i == 0:
                    print(i)
                    exit()
        else:
            aRet = []
            for i in range(1,iRtM+1):
                if iM % i ==0:
                    if iRtM / 2 > i:
                        aRet.append(i)
                        if iD > iM // i :
                            print (iM // i)
                            exit()
                    else:
                        print (i)
                        exit()
            print(max(aRet))
解()

Solution (Python):

iN,iM = [int(_) for _ in input().split()]
iD = iM // iN
if iM % iN == 0:
    print(iD)
elif 2*iN > iM :
    print(1)
else:
    aD = []
    iRtM = int(iM**0.5)
    if iRtM > iD:
        for i in range(iD,0,-1):
            if iM % i == 0:
                print(i)
                exit()
    else:
        aRet = []
        for i in range(1,iRtM+1):
            if iM % i ==0:
                if iRtM / 2 > i:
                    aRet.append(i)
                    if iD > iM // i :
                        print (iM // i)
                        exit()
                else:
                    print (i)
                    exit()
        print(max(aRet))

Solution (Python):
N, M = map(int, input().split())

max_ans = M // N

ans = 1

for n in range(1, int(M ** 0.5) + 1):
    if M % n != 0:
        continue

    if n <= max_ans:
        ans = max(ans, n)
    if M // n <= max_ans:
        ans = max(ans, M // n)

print(ans)

Solution (Python):
import math

N, M = [int(_) for _ in input().split()]


sr = int(math.sqrt(M))

result = 1

for i in range(sr, 0, -1):
    if M % i == 0:
        r = i
        if M >= N * r:
            result = max(r, result)
        r = M // i
        if i >= N:
            result = max(r, result)

print(result)

Solution (Python):
n, m = list(map(int, input().split()))
maxlim = int(m**0.5)+1
minj = m
for j in range(1,maxlim+1):
    rem = m%j
    if rem == 0:
        div = m//j
        if j >= n and j < minj:
            minj = j
        elif div >= n and div < minj:
            minj = div

k = m//minj
print(k)

Solution (Python):
def 解():
    iN,iM = [int(_) for _ in input().split()]
    iD = iM // iN
    if iM % iN == 0:
        print(iD)
    elif 2*iN > iM :
        print(1)
    else:
        aD = []
        for i in range(1,int(iM**0.5)+1):
            if iM % i == 0:
                if iD > i : aD.append(i)
                j = iM // i
                if iD > j :aD.append(j)
        print(max(aD))
解()

Solution (Python):
iN,iM = [int(_) for _ in input().split()]
iD = iM // iN
if iM % iN == 0:
    print(iD)
elif 2*iN > iM :
    print(1)
else:
    aD = []
    for i in range(1,int(iM**0.5)+1):
        if iM % i == 0:
            if iD > i : aD.append(i)
            j = iM // i
            if iD > j :aD.append(j)
    print(max(aD))

Solution (Python):



def get_line():
    return input()


def get_tokens():
    return get_line().split()


def get_ints():
    return [int(_) for _ in get_tokens()]


def main():
    n, m = get_ints()

    divs = []

    div = 1
    while div * div <= m:
        if m % div == 0:
            divs.append(div)
            if div * div < m:
                divs.append(m // div)
        div += 1
        
    divs.sort()
    ratios = [m // div for div in divs]

    i = 0
    while i + 1 < len(divs) and ratios[i + 1] >= n:
        i += 1
    print(divs[i])


if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, input().split())

i = 1
ans = 0
while True:
    if i * i > M + 1:
        break
    j = M // i
    if M % i == 0 and M // i >= N:
        ans = max(ans, i)
    if M % j == 0 and M // j >= N:
        ans = max(ans, j)
    i += 1
    

print(ans)

Solution (Python):
import math
import time
n, m = map(int, input().split())
flag=0
if m%n==0:
    print(m//n)

else:
    start = time.time()
    index=m//n
    while index >0:
        elapsedTime = time.time()-start
        if elapsedTime > 1:
            flag=1
            break
        elif m%index==0:
            print(index)
            break
        index-=1

    if flag==1:
        index = 1
        while index < m+1:
            if m % index == 0:
                if index > n-1:
                    print(m//index)
                    break
            index += 1

Solution (Python):
N, M = [int(i) for i in input().split()]

def canMake(div):
    return (M//div) - (N-1) >= 1 

ans = 1
for i in range(1, M):
    if i * i > M:
        break
    if M % i != 0:
        continue
    a, b = i, M//i
    if canMake(a):
        ans = max(ans, a)
    if canMake(b):
        ans = max(ans, b)
print(ans)

Solution (Python):
N, M = [int(i) for i in input().split()]

def canMake(div):
    
    return N * div <= M

ans = 1
for i in range(1, M):
    if i * i > M:
        break
    if M % i != 0:
        continue
    a, b = i, M//i
    if canMake(a):
        ans = max(ans, a)
    if canMake(b):
        ans = max(ans, b)
print(ans)

Solution (Python):
N,M = map(int,input().split())

m = M
f = {}
while m%2 == 0:
    f[2] = f.get(2,0) + 1
    m = m//2

k = 3
l = int(m**0.5)+1
while m != 1:
    if k > l:
        f[m] = f.get(m,0)+1
        break
    while m%k == 0:
        f[k] = f.get(k,0)+1
        m = m//k
    k += 2
C=[1]
for k in f:
    C_tmp = []
    for c in C:
        for i in range(f[k]):
            C_tmp.append(c*(k**(i+1)))
    C.extend(C_tmp)
ans_r = M
for c in C:
    if c>=N and c<ans_r:
        ans_r = c
print(M//ans_r)

Solution (Python):
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)

Solution (Python):
import math
N,M = map(int,input().split())
rtM = math.floor(math.sqrt(M))
divs = []
for i in range(1,rtM+1):
    if M % i == 0:
        if i <= M/N:
            divs.append(i)
        if M//i <= M/N:
            divs.append(M//i)
print(max(divs))

Solution (Python):
def get_prime_factorized(N):
    R = []
    b, e = 2, 0
    while b ** 2 <= N:
        while N % b == 0:
            N  = N // b
            e += 1
        if e > 0:
            R.append([b, e])
        b, e = b + 1, 0
    if N > 1:
        R.append([N, 1])
    return R

def get_list_divisor(N, reverse=True):
    try:
        F = get_prime_factorized(N)
        L = re_func_divisior(F)
        R = []
        for l in L:
            for i, x in enumerate(l):
                if i == 0:
                    r = x
                else:
                    r *= x
            R.append(r)
        R.sort()
        if reverse == True:
            R.reverse()
    except:
        if N == 1:
            R = [1]
        else:
            R = [N]
    return R

def re_func_divisior(F):
    b, e = F.pop()
    P = re_func_divisior(F) if F else [[]]
    Q = [[b ** k] for k in range(e + 1)]
    return [p + q for p in P for q in Q]


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

for d in get_list_divisor(M, reverse=True):
    if d * N <= M and M % d == 0:
        print(d)
        break

Solution (Python):
from itertools import product

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

max_ans = M // N

ans = 1
tmp = 2
tmpM = M
max_prime = int(M ** 0.5)
all_list = []
i = -1
k = 0
div = 2
while tmpM != 1:
    if tmpM % div == 0:
        tmpM = tmpM // div
        if k == 0:
            i += 1
            all_list.append(set())
            all_list[i].add(div ** k)
            k += 1
        all_list[i].add(div ** k)
        k += 1

    else:
        k = 0
        if div == 2:
            div = 3
        elif div > max_prime:
            div = tmpM
        else:
            div += 2

if all_list == []:
    print(1)
    exit()


ans = 1

for div_tuple in product(*all_list):
    tmp = 1
    for k in div_tuple:
        tmp *= k
        if tmp > max_ans:
            break
    else:
        ans = max(ans, tmp)

print(ans)

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

Solution (Python):
import sys
from collections import deque
import copy
import math
import numpy as np

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def divisor_sub(p, q):
    a = []
    for i in xrange(0, q + 1):
        a.append(p ** i)
    return a

def factorization(n):
    def factor_sub(n, m):
        c = 0
        while n % m == 0:
            c += 1
            n /= m
        return c, n
    
    buff = []
    c, m = factor_sub(n, 2)
    if c > 0: buff.append((2, c))
    c, m = factor_sub(m, 3)
    if c > 0: buff.append((3, c))
    x = 5
    while m >= x * x:
        c, m = factor_sub(m, x)
        if c > 0: buff.append((x, c))
        if x % 6 == 5:
            x += 2
        else:
            x += 4
    if m > 1: buff.append((m, 1))
    return buff

def divisor(n):
    xs = factorization(n)
    ys = divisor_sub(xs[0][0], xs[0][1])
    for p, q in xs[1:]:
        ys = [x * y for x in divisor_sub(p, q) for y in ys]
    return sorted(ys)

def is_prime(x):
    if x < 2: return False
    if x == 2 or x == 3 or x == 5: return True
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [int(input_raw[0]), int(input_raw[1])]
    if N == 1:
        print M
        exit()
    if is_prime(M):
        print 1
        exit()








    max_p = 0
    for p in range(int(math.sqrt(M) + 0.5) , 0, -1):

        if(M % p == 0):
            q = M/p
            if q >= N:
                max_p = max(p, max_p)
            if p >= N:
                max_p = max(q, max_p)
    print max_p

if __name__ == '__main__':
    main()

Solution (Python):
import math
 
N,M = map(int,input().split())
 
ans = 1
for i in range(1,int(math.sqrt(M))+1+1):
  if M % i != 0:
    continue
  B = int(M / i)
  
  if (i * N <= M):
    ans = max(ans,i)
  if (B * N <= M):
    ans = max(ans,B)

print(ans)

Solution (Python):
import time
def primeFactor(N):
    i = 2
    ret = {}
    n = N
    mrFlg = 0
    if n < 0:
        ret[-1] = 1
        n = -n
    if n == 0:
        ret[0] = 1
    while i**2 <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
            ret[i] = k
        if i == 2:
            i = 3
        else:
            i += 2
        if i == 101 and n >= (2**20):
            def findFactorRho(N): 
                def gcd(a, b):
                    if b == 0:
                        return a
                    else:
                        return gcd(b, a % b)
                def f(x, c):
                    return ((x ** 2) + c) % N
                semi = [N]
                for c in range(1, 11):
                    x=2
                    y=2
                    d=1
                    while d == 1:
                        x = f(x, c)
                        y = f(f(y, c), c)
                        d = gcd(abs(x-y), N)
                    if d != N:
                        if isPrimeMR(d):
                            return d
                        elif isPrimeMR(N//d):
                            return N//d
                        else:
                            semi.append(d)

                semi = list(set(semi))
                print (semi)
                s = min(semi)
                for i in [2,3,5,7]:
                    while True:
                        t = int(s**(1/i)+0.5)
                        if t**i == s:
                            s = t
                            if isPrimeMR(s):
                                return s
                        else:
                            break

                i = 3
                while True:
                    if s % i == 0:
                        return i
                    i += 2
                    
            while True:
                if isPrimeMR(n):
                    break
                else:
                    mrFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                        ret[j] = k
                if n == 1:
                    break
        
    if n > 1:
        ret[n] = 1
    if mrFlg > 0:
        def dict_sort(X):
            Y={}
            for x in sorted(X.keys()):
                Y[x] = X[x]
            return Y
        ret = dict_sort(ret)
    return ret

def isPrime(N):
    if N <= 1:
        return False
    return sum(primeFactor(N).values()) == 1

def isPrimeMR(n):
    if n == 2: return True
    if n == 1 or n & 1 == 0: return False

    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    for a in [2, 3, 5, 7, 11, 13, 17, 19]:
        t = d
        y = pow(a, t, n)

        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1

        if y != n - 1 and t & 1 == 0:
            return False

    return True        

def findPrime(N):
    if N < 0:
        return -1
    i = N
    while True:
        if isPrime(i):
            return i
        i += 1

def divisors(N):
    pf = primeFactor(N)
    ret = [1]
    for p in pf:
        ret_prev = ret
        ret = []
        for i in range(pf[p]+1):
            for r in ret_prev:
                ret.append(r * (p ** i))
    return sorted(ret)

N, M = map(int, input().split(" "))
 
for i in divisors(M):
    if i >= N:
        print (M//i)
        break

Solution (Python):
def primeFactor(N):
    i = 2
    ret = {}
    n = N
    if n < 0:
        ret[-1] = 1
        n = -n
    if n == 0:
        ret[0] = 1
    d = 2
    sq = int(n ** (1/2))
    while i <= sq:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
            ret[i] = k
        if k > 0:
            sq = int(n**(1/2))
        if i == 2:
            i = 3
        elif i == 3:
            i = 5
        elif d == 2:
            i += 2
            d = 4
        else:
            i += 4
            d = 2
        
    if n > 1:
        ret[n] = 1
    return ret

def divisors(N):
    pf = primeFactor(N)
    ret = [1]
    for p in pf:
        ret_prev = ret
        ret = []
        for i in range(pf[p]+1):
            for r in ret_prev:
                ret.append(r * (p ** i))
    return sorted(ret)

N, M = map(int, input().split(" "))
 
for i in divisors(M):
    if i >= N:
        print (M//i)
        break

Solution (Python):
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)

Solution (Python):
from math import sqrt, ceil
n, m = map(int, input().split())

M = set()
for i in range(1, ceil(sqrt(m))+1):
    if m % i == 0:
        M.add(i)
        M.add(m//i)
M = sorted(list(M), reverse=True)

for i in M:
    if i <= m // n:
        print(i)
        break

Solution (Python):
import math, collections, itertools, functools, operator
class PrimeUtils:
    @staticmethod
    def primes_sieve(n):
        sieve = [True] * (n + 1)
        for i in range(2, n + 1):
            if sieve[i]:
                for j in range(i + i, n + 1, i):
                    sieve[j] = False
        return [i for i, x in enumerate(sieve[2:], 2) if x]
    @staticmethod
    
    def pfd(n):
        rn = math.ceil(math.sqrt(n))
        primes = PrimeUtils.primes_sieve(rn)

        factors = []
        cur = n
        for p in primes:
            while True:
                div, rem = divmod(cur, p)
                if rem == 0:
                    factors.append(p)
                    cur = div
                else:
                    break
        if cur != 1 or not factors:
            factors.append(cur)
        return factors
    @staticmethod
    
    def factors(n):
        pf = PrimeUtils.pfd(n)
        pfc = collections.Counter(pf)
        ppv = [[pow(p, i) for i in range(n+1)] for p,n in pfc.items()]
        return [functools.reduce(operator.imul, x) for x in itertools.product(*ppv)]

N, M = map(int, input().split())
for factor in sorted(PrimeUtils.factors(M)):
    if N <= factor:
        print(M // factor)
        break
else:
    print(1)

Solution (Python):
import math
N, M = map(int, raw_input().split())

MAX_RES = int(math.sqrt(M))
res = 1
for i in range(1, MAX_RES + 1):
	if i * i > M:
		break
	if M % i != 0:
		continue
	j = M / i
	if i * N <= M:
		res = max(res, i)
	if j * N <= M:
		res = max(res, j)
print res

Solution (Python):
import sys
import math
Input = sys.stdin.readline
 
N, M = map(int, Input().split())
D = []
 
for i in range(int(math.sqrt(M)), 0, -1):
    if M % i == 0:
      D.append(i)
      D.append(M // i)

D.sort(reverse=True)
for d in D:
    if M >= N*d:
        print(d)
        break

Solution (Python):
import math
N, M = map(int, input().split())
_M = M
primes = [1]
prime = 2
for p in range(prime, int(math.sqrt(M))):
  while _M % p == 0:
    primes.append(p)
    _M //= p
    if _M == 1:
      break
  if p >= _M:
    break
if _M > 1:
  primes.append(_M)
ans = 1
devides = [0] * N
if N > 1:
  devides[1] = 1
  for prime in primes:
    _devides = [d for d in devides]
    for i in range(N):
      if devides[i]:
        if i * prime < N:
          _devides[i * prime] = 1
        else:
          ans = max(M // i // prime, ans)
    devides = _devides
else:
  ans = M
print(ans)

Solution (Python):
import math

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

x=int(math.sqrt(m))

ans=1
for i in range(1,x+1):
  if m%i==0:
    if i*n<=m:
      ans=max(ans,i)
    if (m/i)*n<=m:
      ans=max(ans,m/i)
print(int(ans))

Solution (Python):
import math

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

x=int(math.sqrt(m))

ans=1
for i in range(1,x+1):
  if m%i==0:
    if i*n<=m:
      ans=max(ans,i)
    if int(m/i)*n<=m:
      ans=max(ans,int(m/i))
print(ans)

Solution (Python):
N,M= map(int, input().split())
yakusu =[]

for i in range(int(M**(1/2)),0,-1):
    if M % i == 0:
        yakusu.append(i)
        yakusu.append(int(M/i))

yakusu.sort(reverse=True)

for i in yakusu:
    if i <= M/N:
        print(i)
        break

Solution (Python):
import math
N,T  = list(map(int,input().split()))

m = []

def ans():
    ans = 1
    for i in range(1,int(math.sqrt(T))):    
            if T % i ==0:
                m.append(i)
                m.append(T//i)
    for p in m:
        if p <= T // N:
            ans = max(ans,p)
    print (ans)
    
if T % N == 0:
    print (int(T / N))
else:
    ans()

Solution (Python):
def d_partition(N, M):
    if N == 1:
        return M  

    def divisor_list(n):
        
        ret = []
        for k in range(1, int(n**0.5) + 1):
            if n % k == 0:
                ret.extend([k, n // k])
        ret.sort()
        return ret

    divisor_m = divisor_list(M)
    ans = -1
    for d in divisor_m:
        if d <= M // N:
            ans = d
        else:
            break
    return ans

N, M = [int(i) for i in input().split()]
print(d_partition(N, M))

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

Solution (Python):
import math

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




def pfac(n):
    values = [1, n]
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            values.append(i)
            values.append(n // i)
    return values

L = pfac(M)
L = [i for i in L if i * N <= M]

ans = []
for i in L[::-1]:
    if (M - (N * i)) % i == 0:
    
        ans.append(i)
print(max(ans))

Solution (Python):
n, m = map(int, input().split())

lstDiv = []
k = 1
while k * k <= m:
    div, r = divmod(m, k)
    if r == 0:
        lstDiv.append(k)
        lstDiv.append(div)
    k += 1

lstDiv = sorted(lstDiv, reverse=True)

for div in lstDiv:
    if div * n <= m:
        print(div)
        break

Solution (Python):
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)

Solution (Python):
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()

Solution (Python):
import math

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




def pfac(n):
    values = [1, n]
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            values.append(i)
            values.append(n // i)
    return values

L = pfac(M)
L = [i for i in L if i * N <= M]

ans = []

for i in L[::-1]:
    if (M - (N * i)) % i == 0:
    
        ans.append(i)

print(max(ans))

Solution (Python):
import math

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




def pfac(n):
    values = [1, n]
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            values.append(i)
            values.append(n // i)
    return values

L = pfac(M)
L = [i for i in L if i * N <= M]

ans = []

for i in L[::-1]:
    
    if M % i == 0:
        ans.append(i)

print(max(ans))

Solution (Python):
n,m=map(int,input().split())
mm=[]
for i in range(1,int(m**0.5+1)):
    if m%i==0:
        mm.append(i)
        mm.append(m//i)

mm.sort(key=lambda x:-x)
for i in mm:
    if i<=m/n:
        print(i)
        break

Solution (Python):
from math import sqrt, floor
 
N, M = map(int,input().split())
 
rootM = floor(sqrt(M))
l = []
for i in range(1, rootM +1):
    if M % i == 0:
        l.append(i)
        l.append(M//i)
        
ans = 1
for li in l:
    ans = max(ans, li) if li <= M // N else ans
print(ans)