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):
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)

Solution (Python):
import math

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

diff = float("inf")
res = 0
for i, j in array:
    if i >= n:
        res = max(res, j)
    if j >= n:
        res = max(res, i)
print(res)

Solution (Python):
import sys

def main():
  input = sys.stdin.readline
  N, M = map(int, input().split())
  H = 1
  for i in range(int(M//N), 1, -1):
    if M % i == 0:
      H = i
      break

  print(H)

if __name__ == '__main__':
  main()

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

Solution (Python):
N,M=map(int,input().split())
ans=0
for i in range(1,10**5):
    if M%i==0:
        a=max(M//i,i)
        b=min(M//i,i)
        if M//a>=N and ans<a:
            ans=a
        if M//b>=N and ans<b:
            ans=b
print(ans)

Solution (Python):
n, m = map(int, input().split())
ans = 1
if n == 1:
    ans = m
else:
    for i in range(1, min(m // n + 1, int(m ** 0.5) + 1))[::-1]:
        if m % i == 0:
            ans = max(ans, i)
            if i >= n:
                ans = max(ans, m // i)
print(ans)

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

Solution (Python):


n,m=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(key=lambda x:-x)

for d in divisors:
    if d<=m//n:
        print(d)
        break

Solution (Python):



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

ans = 1
x = 1
a = []

while x * x <=M:
 if M%x==0:
  a.append(x)
  a.append(M/x)
  
 x+=1
 


for i in a:
 if M/i >= N:
  ans = max(ans,i)
print ans

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


def init() -> None:
    i = 1
    while i ** 2 <= m:
        if m % i == 0:
            candidates.add(i)
            candidates.add(m // i)
        i += 1


def main() -> None:
    init()
    ans = 0
    for candidate in candidates:
        if candidate * n <= m:
            ans = max(ans, candidate)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import math

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


ans = 0
for i in range(1, math.ceil(math.sqrt(m))+1):
    if m % i == 0:
        if min(i, m//i) >= n:
            ans = max(ans, max(i, m//i))
        elif max(i, m//i) >= n:
            ans = max(ans, min(i, m//i))
print(ans)

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

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

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

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

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

res = []
for i in range(1, int(math.sqrt(M))+1):
    if M % i == 0:
        res.append(i)
        res.append(M//i)
res.sort()
print(res[bisect.bisect_right(res, M//N)-1])

Solution (Python):
import numpy as np
flag = True
N, M = map(int, input().split())
ans = 0
for i in range(1, int(np.sqrt(M)) + 2):
    if M % i == 0:
        if min(M // i, i) >= N:
            ans = max(ans, max(M // i, i))
        elif max(M // i, i) >= N:
            ans = max(ans, min(M // i, i))

print(ans)

Solution (Python):
def s(n):
    return[m(t)for t in d(f(n))]
def f(n):
    l=[]
    b,e=2,0
    while b*b<=n:
        while not n%b:
            n//=b
            e+=1
        if e:
            l.append((b,e))
        b,e=b+1,0
    if n>1:
        l.append((n,1))
    return l
def d(l):
    b,e=l.pop()
    p=d(l)if l else[[]]
    v=[[(b,k)]for k in range(e+1)]
    return[s+t for s in p for t in v]
def m(l):
    a=1
    for b,e in l:
        a*=b**e
    return a
N,M=map(int,input().split())
if M<2:print(1);exit()
a=0
for i in sorted(s(M))[::-1]:
    if M//i>=N:
        a=i
        break
print(a)

Solution (Python):
def s(n):
    return[m(t)for t in d(f(n))]
def f(n):
    l=[]
    b,e=2,0
    while b*b<=n:
        while not n%b:
            n//=b
            e+=1
        if e:
            l.append((b,e))
        b,e=b+1,0
    if n>1:
        l.append((n,1))
    return l
def d(l):
    b,e=l.pop()
    p=d(l)if l else[[]]
    v=[[(b,k)]for k in range(e+1)]
    return[s+t for s in p for t in v]
def m(l):
    a=1
    for b,e in l:
        a*=b**e
    return a
N,M=map(int,input().split())
if M<2:print(1);exit()
a=0
for i in sorted(s(M))[::-1]:
    if M//i>=N:
        a=i
        break
print(a)

Solution (Python):

import math

class Prime:
    seed_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

    def is_prime(self, n):
        is_prime_common = self.is_prime_common(n)
        if is_prime_common is not None:
            return is_prime_common

        if n < 2000000:
            return self.is_prime_bf(n)
        else:
            return self.is_prime_mr(n)

    def is_prime_common(self, n):
        if n == 1: return False
        if n in Prime.seed_primes: return True
        if any(map(lambda x: n % x == 0, self.seed_primes)): return False

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

    def is_prime_mr(self, n):
        d = n - 1
        while d % 2 == 0:
            d //= 2

        witnesses = self.get_witnesses(n)

        for w in witnesses:
            y = pow(w, d, n)

            while d != n - 1 and y != 1 and y != n - 1:
                y = (y ** 2) % n
                d *= 2

            if y != n - 1 and d % 2 == 0:
                return False

        return True

    def get_witnesses(self, num):
        def _get_range(num):
            if num < 2047:
                return 1
            if num < 1373653:
                return 2
            if num < 25326001:
                return 3
            if num < 3215031751:
                return 4
            if num < 2152302898747:
                return 5
            if num < 3474749660383:
                return 6
            if num < 341550071728321:
                return 7
            if num < 38255123056546413051:
                return 9
            return 12

        return self.seed_primes[:_get_range(num)]

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

    @staticmethod
    def f(x, n, seed):
        p = Prime.seed_primes[seed % len(Prime.seed_primes)]
        return (p * x + seed) % n

    def find_factor(self, n, seed=1):
        if self.is_prime(n):
            return n

        x, y, d = 2, 2, 1
        count = 0
        while d == 1:
            count += 1
            x = self.f(x, n, seed)
            y = self.f(self.f(y, n, seed), n, seed)
            d = self.gcd(abs(x - y), n)

        if d == n:
            return self.find_factor(n, seed+1)
        return self.find_factor(d)

    def find_factors(self, n):
        primes = {}
        if self.is_prime(n):
            primes[n] = 1
            return primes

        while n > 1:
            factor = self.find_factor(n)

            primes.setdefault(factor, 0)
            primes[factor] += 1

            n //= factor

        return primes

prime = Prime()

def main():
    [N, M] = list(map(int, input().split()))

    prime = Prime()

    factors = prime.find_factors(M)

    max_g = M // N
    g = 1
    d = [1]
    for p, n in factors.items():
        nd = []
        for v in d:
            for k in range(n + 1):
                m = p ** k
                if v * m <= max_g:
                    g = max(g, v * m)
                    nd.append(v * m)
                else:
                    break
        d = nd


    print(g)


if __name__ == '__main__':
    main()

Solution (Python):
import math

S = list(map(int,input().split()))
N = S[0]
M = S[1]
div = list()
z = math.sqrt(M)
z = math.ceil(z)

for x in range(1,z):
    if M % x == 0:
        div.append(x)
        div.append(M//x)
div.append(M)
div.append(N)

sorted_div = sorted(div)
n = sorted_div.index(N)

y =sorted_div[n+1]

ans = M // y

print(ans)

Solution (Python):

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

    return ans       


N,M = list(map(int,input().split()))
a = devisor(M)
a.sort(reverse = True)

for i in a:
    check = M//i
    if check >= N:
        print(i)
        break

Solution (Python):
def main():
    n, m = map(int, input().split())
    if n == 1:
        print(m)
        return
    i = 1
    ans = 1
    while i*i <= m:
        if m % i != 0:
            i += 1
            continue
        a = i
        if m // i >= n:
            ans = max(ans, i)
        if m // (m // i) >= n:
            ans = max(ans, m // i)
        i += 1
    print(ans)
    
if __name__ == '__main__':
    main()

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

maxnum = m//n

for i in range(maxnum,0,-1):
  if m%i==0:
    print(i)
    break

Solution (Python):
def main():
    N, M = map(int, input().split())
    if N == 1:
        print(M)
    else:
        ans = 0
        for i in range(1, int(M ** 0.5)):
            if M % i != 0:
                continue
            if M >= i * N:
                ans = max(i, ans)
            if M >= M // i * N:
                ans = max(M // i, ans)

        print(ans)


if __name__ == '__main__':
    main()

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

ans = 0
for i in range(1, m//n+1):
    if m % i == 0:
        ans = max(ans, i)
        if m // i > i and m // i <= m // n:
            ans = max(ans, m // i)
            break
            
print(ans)

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

for i in range(1, a + 1):
    if m % i == 0:
        ans = i
        if (m // i) > i and (m // i) <= a:
            ans = m // i
            break
        
print(ans)

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

upper = m//n
ans = 0
for i in range(1, upper+1):
    if m % i == 0:
        ans = i
        if (m // i) > i and (m // i) <= upper:
            ans = m // i
            break

print(ans)

Solution (Python):
import math
import bisect


def all_divisor(n):
  i = 1
  divisor_small = []
  divisor_large = []
  if n == 1:
    return [1]
  else:
    while i * i <= n:
      if n % i == 0:
        divisor_small.append(i)
        divisor_large.append(n // i)
      i += 1
  divisor_large.reverse()
  divisor = divisor_small + divisor_large 
  return divisor

n,m = map(int, input().split())
divisor = all_divisor(m)
max_div = m // n
insert_index = bisect.bisect(divisor,max_div)
print(divisor[insert_index-1])

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

Solution (Python):
n, m = map(int, input().split())
a = m // n
ans = 0

for i in range(1, a + 1):
    if m % i == 0:
        ans = i
        
        if (m // i) > i and (m // i) <= a:
            ans = m // i
            break
        
print(ans)

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

ans = 1
for g in range(1, int(M ** 0.5) + 1):
    if M % g == 0 and M / g >= N:
        ans = max(ans, g)
    
    if M % g == 0:
        g2 = M // g
        if M % g2 == 0 and M / g2 >= N:
            ans = max(ans, g2)
print(ans)

Solution (Python):
import math as m
N,M = map(int,input().split())
divisor = []
for i in range(1,m.floor(pow(M,1/2)) + 1):
  if M % i == 0:
    divisor.append(i)
    divisor.append(M // i)
ans = 1
for e in divisor:
  if e > ans and e <= M // N:
    ans = e
print(ans)

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

if N == 1:
    print(M)
    exit()

judge = "prime"
for i in range(m.floor(pow(M,1/2)),1,-1):
    if M % i == 0:
        judge = "conposite"
        break
if judge == "prime":
    print(1)
    exit()
for i in range(M // N,0,-1):
    if M % i == 0:
        print(i)
        exit()

Solution (Python):
n, m = map(int, input().split())
divisors = []
for i in range(1,m+1):
    if i * i > m:
        break
    if i * i == m:
        divisors.append(i)
        break
    if m % i == 0:
        divisors.append(i)
        divisors.append(m // i)
ans = filter(lambda d: d <= m//n, divisors)
print(max(ans))

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

def yakusu(m):
    y = []
    for i in range(1, math.ceil(math.sqrt(m))+1):
            if m % i == 0:
                y.extend([i, m//i])
    return y

if M % N == 0:
    print(M//N)
else:
    yaku = sorted(yakusu(M))
    for yi in yaku:
        if yi < N:
            continue
        else:
            break
    print(M//yi)

Solution (Python):
primes = []
MAX_NUM = 100000
is_prime = [True] * MAX_NUM
is_prime[0] = False
is_prime[1] = False
for num in range(MAX_NUM):
    if is_prime[num]:
        primes.append(num)
        for j in range(2*num, MAX_NUM, num):
            is_prime[j] = False

def do_prime_factorization(x):
    res = {}
    for p in primes:
        if x == 1:
            break
        while x % p == 0:
            x /= p
            if not p in res:
                res[p] = 0
            res[p] += 1
    if x > 1:
        res[x] = 1
    return res.items()

def f(x, d, n, m, ps):
    if x >= n:
        return x
    if d < 0:
        return m
    p, num = ps[d]
    res = m
    for i in range(num+1):
        y = x * (p**i)
        res = min(res, f(y, d-1, n, m, ps))
    return res

def solve(n, m):
    ps = do_prime_factorization(m)
    q = f(1, len(ps)-1, n, m, ps)
    p = m // q
    return p

n, m = map(int, raw_input().split())
print(solve(n, m))

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

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

upper=M/N
def factorize(n):
    fct = []
    b, e = 2, 0
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct
def divisorize(fct):
    b, e = fct.pop()
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]
def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

fct = factorize(M)
if fct==[]:
    print 1
    exit()

Ans=1
for div in divisorize(fct):
    if num(div)<=upper:
        Ans=max(Ans,num(div))
   
print Ans

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

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

ans=0

if n==1:
  print(m)
else:
  a=int(m**0.5)

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

Solution (Python):
n, m = map(int, input().split())
if n == 1:
  print(m)
  exit()
if n < int(m**(1/2)):
  for divide in range(n,int(m**(1/2))+1):
    if m % divide == 0:
      print(int(m/divide))
      exit()
  for divide in range(n,0,-1):
    if m % divide == 0:
      print(divide)
      exit()
else:
  for divide in range(m//n,0,-1):
    if m % divide == 0:
      print(divide)
      exit()

Solution (Python):


from math import sqrt

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

for k in range(1, int(sqrt(M)) + 1):
    if M % k == 0:
        if k <= M / N:
            ans = max(ans, k)
        if M/k <= M/N:
            ans = max(ans, M//k)
print(ans)

Solution (Python):
import math
N,M = map(int, input().split())
L = []
 
for i in range(1,math.floor(math.sqrt(M))+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))

Solution (Python):
import math
N, M = map(int, input().split())
yakusuu = [] 
for i in range(int(math.sqrt(M))):
  if M%(i+1) == 0:
    yakusuu +=[i+1]
    yakusuu +=[M//(i+1)]
yakusuu.sort(reverse=1)

for p in yakusuu:
  if p <= M/N:
    print(p)
    break

Solution (Python):
import math
N,M = map(int,input().split())
Max = 1
for m in range(1,int(math.sqrt(M))+1):
    if M%m == 0 and m <= M//N :
        if Max < m:
            Max = m
        if M//m <= M//N and Max < M//m :
            Max = M//m
            
print(Max)

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

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

ans = 1
for i in range(1, int(sqrt(m)) + 1):
    if m % i == 0:
        if m // i >= n:
            ans = max(ans, i)
        if i >= n:
            ans = max(ans, m // i)

print(ans)

Solution (Python):


"""
参考：http://drken1215.hatenablog.com/entry/2018/11/06/120600
　　　https://emtubasa.hateblo.jp/entry/2018/10/06/224022
・約数とか。理解は出来たものの、自分で気付けるにはどうすれば…。
・この前作ったけど使えなかった約数列挙ライブラリが役に立った。
"""

from math import sqrt

def num_div_set2(N):
    
    s = {1, N}
    
    end = int(sqrt(N)) + 1
    for i in range(2, end+1):
        
        if N % i == 0:
            s.add(i)
            s.add(N // i)
    return s

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

ans = 1
for d in num_div_set2(M):
    
    
    if d * N <= M:
        ans = max(d, ans)
print(ans)

Solution (Python):
N, M = map(int,input().split())
a, b = 1, M
divisor = []
while a <= b:
    if a * b == M:
        divisor.append(a)
        divisor.append(b)
    a = M // b + 1
    b = M // a
divisor.sort()
for i in divisor:
    if i >= N:
        print(M // i)
        break

Solution (Python):
import itertools
import math



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

P = []
F = []
M_ = M
for n in range(2, int(math.sqrt(M))+1):
    num = 0
    while M_ % n == 0:
        M_ /= n
        num +=1
    if num != 0:
        P.append(n)
        F.append(num)
if M_ != 1:
    P.append(M_)
    F.append(1)

min_A = M
for F_ in itertools.product(*list(map(lambda i: range(i+1), F))):
    A = 1
    for p,f in zip(P,F_): A *= pow(p,f)
    if A >=N and A < min_A: min_A = A

print(int(M/min_A))

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

def yaku(N):
    res = []
    for i in range(1, round(N**(1/2)) + 3 ):
        if N%i == 0:
            res.append(i)

    res2 = [N//i for i in res]
    res = list(set(res + res2))
    return res


import bisect

L = yaku(M)

L.sort()
ii = bisect.bisect_left(L,N)

print(M//L[ii])

Solution (Python):


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


import math
plist = [2]
for i in range(3, int(1e5+1)):
    ok = True
    for j in plist:
        if j > math.sqrt(i):
            break   
        elif i % j == 0:
            ok = False
            break
    if ok:
        plist.append(i)





prime_pair = {}

def cnt_power(n, p):
    if p < 2:
        raise "p is smaller than 2."
    if n >= p and n % p == 0:
        return 1 + cnt_power(int(n/p), p)
    else:
        return 0
        
def fac(N):
    global prime_pair
    for p in plist:
        if N % p == 0:  
            
            
            prime_pair[p] = cnt_power(N, p)


fac(M)

import copy
divisor = []
init_nowpair = {}
for k in prime_pair:
    
    init_nowpair[k] = 0


def makedivisor(prime_pair, now_pair):
    
    multi = 1
    for np in now_pair:
        multi *= int(pow(np, now_pair[np]))
    
    
    if multi > M:
        return 
    else:
        if not multi in divisor:
            divisor.append(multi)
        else:
            return 
    

    for np in now_pair:
        if prime_pair[np] > now_pair[np]:
            now_pair2 = copy.deepcopy(now_pair)
            now_pair2[np] += 1
            makedivisor(prime_pair, now_pair2)
makedivisor(prime_pair, init_nowpair)            
divisor.sort()


maxx = 0
for d in divisor:
    if M % d == 0 and int(M/d) >= N:
        maxx = max(maxx, d)

print(maxx)

Solution (Python):
import math

N,M = list(map(int,input().strip().split()))
ans = 1
i = 0

def is_prime(num):
    if num < 2:
        return False
    if num == 2 or num == 3 or num == 5:
        return True
    if num % 2 == 0 or num % 3 == 0 or num % 5 == 0:
        return False

    prime = 7
    step = 4
    num_sqrt = math.sqrt(num)
    while prime <= num_sqrt:
        if num % prime == 0:
            return False
        prime += step
        step = 6 - step

    return True

if is_prime(M) == False:
    while M//2 >= N+i:
        if M%(N+i) == 0:
            ans = M//(N+i)
            break
        else:
            i += 1

print(ans)

Solution (Python):
import math

def factoring(x):
    ans = []
    for i in range(1, int(math.sqrt(x))+1):
        if x%i == 0:
            ans.append(i)
            ans.append(x // i)
    return sorted(ans)

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

facts = factoring(m)
for i in facts[::-1]:
    if i <= int(m/n):
        print(i)
        exit()

Solution (Python):
import math

def factoring(x):
    ans = []
    for i in range(1, int(math.sqrt(x))+1):
        if x%i == 0:
            ans.append(i)
            ans.append(x // i)
    return sorted(ans)

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

facts = factoring(m)
ans = 1
for i in facts[::-1]:
    if i <= int(m/n):
        print(i)
        exit()
print(ans)

Solution (Python):
import math

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

p = []

for i in range(1,int(math.sqrt(m))+1):
    if (m % i) == 0:
        p += [i,m//i]

ret = 1
for i in p:
    if m // i >= n:
        ret = max(ret,i)

print(ret)

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

for i in xrange(m/n, 0, -1):
    if m % i == 0:
        print i
        break

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

Solution (Python):
import sys
n,m=map(int,input().split())
a=m//n
ans=1
if m%n==0:
  print(int(m//n))
  sys.exit()
for i in range(1,a+1):
    if m%i==0:
        ans=max(ans,i)
print(ans)

Solution (Python):
def find_prime_factor(num):
    if num & 1 == 0:
        return 2
    for i in range(3, int(num ** (1 / 2)) + 1):
        if num % i == 0:
            return i
    return num


def prime_factorization(num):
    subtract = num
    result = []
    while subtract > 1:
        factor = find_prime_factor(subtract)
        result.append(factor)
        subtract //= factor
    return result


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

prime_factors = prime_factorization(m)

power = {}
for prime in prime_factors:
    if prime in power:
        power[prime] += 1
    else:
        power[prime] = 1


divisors = [1]
for prime in power:
    divisors += [divisor * prime ** pw
                 for pw in range(1, power[prime] + 1)
                 for divisor in divisors]
divisors.sort()

answer = 0
for divisor in divisors:
    if divisor <= int(m / n):
        answer = divisor
    else:
        break

print(answer)

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

div = []
sqrt_m = int(math.sqrt(m))
for i in range(1, sqrt_m + 1):
    if m % i == 0:
        div.append(i)
        div.append(m // i)

div.sort(reverse=True)
for i in div:
    if m >= i * n and (m - i * n) % i == 0:
        print(i)
        exit()

Solution (Python):
import math
N, M = map(int,input().split())
P = [1]
for k in range(2,math.floor(math.sqrt(M))+1):
    if M % k == 0:
        P.append(k)
        P.append(M//k)
P = sorted(P)
if N == 1:
    print(M)
    exit(0)

ans = 1
for p in P:
    if p*N <= M:
        ans = p

print(ans)

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def divisors(m: int):
    i = 1
    div = []
    while i*i <= m:
        if m%i == 0:
            div.append(i)
            div.append(m//i)
        i += 1
        
    return list(set(div))

n,m = li()

divs = divisors(m)

ans = 1
for di in divs:
    if n*di <= m:
        ans = max(ans, di)

print(ans)

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):
        p, q = divmod(m, k)

        if q == 0 and p * n <= m:
            ans = max(ans, p)

        if q == 0 and m // p * n <= m:
            ans = max(ans, m // p)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N,M = map(int,input().split())
divs = set()
n = 1
while n*n <= M:
    if M%n == 0:
        divs.add(n)
        divs.add(M//n)
    n += 1

ans = 0
for d in divs:
    if d*N <= M:
        ans = max(ans, d)
print(ans)

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

divs = set()
n = 1
while n*n <= M:
    if M%n == 0:
        divs.add(n)
        divs.add(M//n)
    n += 1

ans = 0
for d in divs:
    if d <= M//N:
        ans = max(ans,d)
print(ans)

Solution (Python):

import itertools
from collections import Counter

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

def primes(n):
    primfac = []
    d = 2
    while d*d <= n:
        while (n % d) == 0:
            primfac.append(d)  
            n //= d
        d += 1
    if n > 1:
       primfac.append(n)
    return primfac


mod = M % N
div = M // N
if mod == 0:
    print(M//N)
    exit()

f = primes(M)


if len(f) == 1:
    print(1)
    exit()

cnt = Counter(f)
ans_list = []

tmp_list = []
for k,v in cnt.items():
  tmp_list.append([i for i in range(v+1)])



for p in itertools.product(*tmp_list):
    tmp = 1
    for k,i in zip(cnt.keys(),p):
        tmp = tmp * (k ** i)

    if tmp > N:
        ans_list.append(M//tmp)

if len(ans_list) == 0:
    print(1)
else:
    print(max(ans_list))

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

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

Solution (Python):

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

Q=M//N 
R=M%N  
'''
if Q>R :
    k=int((Q-R)//(1+N))
    k-=1
    Q -= k
    R += k*N
    '''
memo=0
while R%Q != 0:
    k= int((Q-R%Q)//(N+R//Q+1))   
    
    while (R+k*N)//(Q-k) > memo:
        k -= 1
        
    if k > 0:
        Q -= k
        R += k*N
        memo=R//Q
    else:
        Q -= 1
        R += N
        memo=R//Q

print(Q)

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

def divisor(m):
    ans = []
    for i in range(1, int(math.sqrt(m)) + 1):
        if m % i == 0:
            ans.append(i)
            ans.append(m // i)

    return sorted(ans)


divs = divisor(m)
j = len(divs) - 1
while True:
    if divs[j] * n <= m:
        print(divs[j])
        break
    j -= 1

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

p = m // n
while m % p != 0:
    p -= 1

print(p)

Solution (Python):
from math import *

N, M = map(int, input().split())
special_value = M//N
divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
divisor_set = divisor_set.union(M//j for j in divisor_set)
print(int(max(divisor_set, key=lambda x: x if special_value >= x else -1)))

Solution (Python):
from math import *

def main():
    N, M = map(int, input().split())
    special_value = M//N
    divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
    divisor_set = divisor_set.union(M//j for j in divisor_set)
    print(int(max(divisor_set, key=lambda x: x if special_value >= x else -1)))

    return

if __name__ == "__main__":
    main()

Solution (Python):
from math import *

N, M = map(int, input().split())
special_value = M//N
divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
divisor_set = divisor_set.union(M//j for j in divisor_set)
print(int(max(divisor_set, key=lambda x: x if special_value >= x else -1)))

Solution (Python):
from math import *

def main():
    N, M = map(int, input().split())
    special_value = M//N
    divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
    divisor_set = divisor_set.union(M//j for j in divisor_set)
    print(int(max(divisor_set, key=lambda x: x if special_value >= x else -1)))

    return

main()

Solution (Python):
from math import *

def main():
    N, M = map(int, input().split())
    special_value = M//N
    divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
    divisor_set = divisor_set.union(M//j for j in divisor_set)
    print(int(max([i for i in divisor_set if special_value >= i])))
    return

main()

Solution (Python):
from math import *
N, M = map(int, input().split())
special_value = M//N
divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
divisor_set = divisor_set.union(M//j for j in divisor_set)
print(int(max([i for i in divisor_set if special_value >= i])))

Solution (Python):
from math import *

def main():
    N, M = map(int, input().split())
    special_value = M//N
    divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
    divisor_set = divisor_set.union(M//j for j in divisor_set)
    print(int(max(divisor_set, key=lambda x: x if special_value >= x else -1)))

    return

main()

Solution (Python):
from math import *

def main():
    N, M = map(int, input().split())
    if N==1:
        print(M)
        return
    special_value = M//N
    divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
    divisor_set = divisor_set.union(set(M//j for j in divisor_set))
    print(int(max([i for i in divisor_set if special_value >= i])))

    return

main()