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



Sample input:
3 14


Sample output:
2

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def make_divisors(n):
    divisors = []
    for i in range(1, int(pow(n, 0.5)) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    divisors.sort()
    return divisors


def resolve():
    n, m = map(int, input().split())

    ma = m // n
    div = make_divisors(m)
    res = 1
    for d in div:
        if d <= ma:
            res = d
        else:
            break

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int):
    for d in reversed(range(1, M // N + 1)):
        if M % d == 0:
            print(d)
            return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

for d in divs:
    if M//d>=N:
        print(d)
        exit()

Submission status: Accepted

Solution code:
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
l=make_divisors(m)
l.sort()
a=[li for li in l if li >=n][0]
print(m//a)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
num=m//n

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
make=make_divisors(m)
make.sort()
import bisect
ans=bisect.bisect_right(make,num)
print(make[ans-1])

Submission status: Accepted

Solution code:
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=map(int,input().split())
A=make_divisors(m)
ans=0
for i in A:
    if m%i==0 and n<=m//i:
        ans=max(ans,i)
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import itertools
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, stdin.readline().strip().split()))
so=make_divisors(M)
so.sort(reverse=True)
for i in so:
    if M>=i*N:
        print(i)
        exit()

Submission status: Accepted

Solution code:
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 = map(int, input().split())

for i in make_divisors(m):
    if i >= n:
        print(m // i)
        break

Submission status: Accepted

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

from fractions import gcd

def make_divisors(n: int):
    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

divisors = make_divisors(M)

ans = 0
for i in range(len(divisors)):
    d = divisors[i]
    if d*(N-1) >= M:
        continue
    ans = max(ans, gcd(d, M-(d*(N-1))))

print(ans)

Submission status: Accepted

Solution code:
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()
    divisors=divisors[::-1]
    return divisors
n,m=map(int,input().split())

divisors=make_divisors(m)

for i in divisors:
    if i<=m/n:
        print(i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

#約数列挙
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 = na()
k = m/n
a = make_divisors(m)
ans = 0
for i in a:
    if i <= k:
        ans = max(ans,i)

print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
def prime(x):
  ret = []
  i = 1
  while i*i <= x:
    if x%i == 0:
      ret.append(i)
      if x != i*i:
        ret.append(x//i)
    i += 1
  return sorted(ret)
for i in prime(m)[::-1]:
  if i*n <= m:
    print(i)
    exit(0)

Submission status: Accepted

Solution code:
import sys
import collections
from math import ceil
ma = lambda : map(int,input().split())
ni = lambda : int(input())
def divisor(n):
    d = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            d.append(i)
            if i != n//i:
                d.append(n//i)
    #d.sort()
    return d
n,m = ma()
gcd = 1
D = divisor(m)
for d in D:
    q,r = divmod(m,d)
    if q>=n and r==0:gcd = max(gcd,d)
print(gcd)

Submission status: Accepted

Solution code:
# (o) recursionはダメ
# (o) 素因数はO(sqrt(N))で求められる
# (x) 具体的な計算

"""
Memo:
- A=[a1,...,an]の最大公約数をDとする
- sum(A)=MもDで割り切れる，よってDはMの約数 (Mも割れる)

2条件
- DがMの約数であって，M >= N * Dであるとき
    - a1=...=an-1=D, an = M - (N - 1) * D は全てDで割り切れる (最大公約数)
- Mの約数かつM // N以下の整数で最大
"""

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


# 約数を求める
factors = []
i = 1
while i * i <= M + 1:
    if M % i == 0:
        factors.append(i)
        if M // i != i:
            factors.append(M // i)
    i += 1

factors.sort(reverse=True)
# Mの約数でM // N以下の最大
for f in factors:
    if M // f >= N:
        print(f)
        exit()

# ans = 1
# for factor in factors:
#     if factor <= M // N:
#         ans = factor
# print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def make_divisors(n):  # nの約数を列挙
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort(reverse=True)
    return divisors

N, M = lr()
primes = make_divisors(M)
answer = 1
for p in primes:
    if p * N <= M:
        answer = p
        break
print(answer)
# 10

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
def divisors(n):
  div=[]
  for i in range(1,int(n**0.5)+1):
    if n%i==0:
      div.append(i)
      if not i==n//i:
        div.append(n//i)
  div=sorted(div)[::-1]
  return div
ans=1
for i in divisors(m):
  if m-i*(n-1)>0:
    ans=i
    break
print(ans)

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


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

    # divisors.sort()
    return divisors


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


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

    if N == 1:
        return print(M)

    divisors = make_divisors(M)
    divisors.sort(reverse=True)
    for r in divisors[1:]:
        if M // r < N:
            continue
        else:
            return print(r)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

    divisors.sort(reverse = True)
    return divisors

a = md(m)
ans = 1
for i in a:
    if i >= n:
        ans = m//i
        
print(ans)

Submission status: Accepted

Solution code:
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 = make_divisors(m)
for i in div[::-1]:
    if i <= m / n:
        print(i)
        break

Submission status: Accepted

Solution code:
import sys


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


sys.setrecursionlimit(10 ** 9)


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

    def make_divisors(n):
        divisors = []
        cnt = 0
        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

    divisor = make_divisors(M)
    cnt = len(divisor)
    for i in range(cnt):
        if M // divisor[cnt - i - 1] >= N:
            print(divisor[cnt - i - 1])
            return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
k = m
for i in range(1, int(m**0.5) + 1):
    if m % i:
        continue
    if i >= n:
        print(m // i)
        break
    if m // i >= n:
        k = i
else:
    print(k)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
k = m
for i in range(1, int(m**0.5) + 1):
    if m % i:
        continue
    if i >= n:
        print(m // i)
        break
    if m // i >= n:
        k = i
else:
    print(k)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=m//n #gの下限値

def make_divisors(n):
    D=[]
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            D.append(i)
            if i!=n//i:
                D.append(n//i)
    return list(sorted(D))

D=make_divisors(m)
ans=1

for d in D:
    if d>l:
        continue
    if m//d>=n:
        ans=d

print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
from math import sqrt,ceil
N,M=map(int,input().split())
yakusuu=[]
for i in range(ceil(sqrt(M))):
    if M%(i+1)==0:
        yakusuu.append(i+1)
        yakusuu.append(M//(i+1))
yakusuu.sort()
#print(yakusuu)
for i in range(len(yakusuu)):
    if yakusuu[i]>=N:
        print(M//yakusuu[i])
        break

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
def f(x):
  d = []
  for i in range(1, int(x**0.5)+1):
    if x % i == 0:
      d.append(i)
      if i != x // i:
        d.append(x//i)
  d.sort(reverse = True)
  return d
for i in f(m):
  if m // i >= n:
    print(i)
    quit()

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

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(n//i)
            if i != n // i:
                divisors.append(n//(n//i))

    divisors.sort()
    return divisors


divisors_M = make_divisors(M)

Max = bisect_left(divisors_M,N)
print(M // divisors_M[Max])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  ans=1
  if n==1:
    return m
  for i in range(1,int(math.sqrt(m)+1)):
    if m%i==0:
      if i*n>m:
        continue
      ans=max(ans,i)
      x=m//i
      if x*n>m:
        continue
      ans=max(ans,x)

  return ans

# main()
print(main())

Submission status: Accepted

Solution code:
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


cnd = make_divisors(m)

for i in range(len(cnd)):
    if m // cnd[i] >= n:
        print(cnd[i])
        exit()

Submission status: Accepted

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

Submission status: Accepted

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


def divisor(x):
    div = []
    div_append = div.append
    for i in range(1, int(x**.5)+1):
        if x % i == 0:
            div_append(i)
            div_append(x//i)
    div.sort()
    return div


div = divisor(m)
for d in div[::-1]:
    if m // n >= d:
        ans = d
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import collections

sys.setrecursionlimit(10**6)
N, M = map(int, input().split())

def factor(m):
    fac = collections.Counter()
    while (m&1) == 0:
        m >>= 1
        fac[2] += 1
    for p in range(3, m, 2):
        if p*p > m:
            break
        while m % p == 0:
            m //= p
            fac[p] += 1
    if m > 1:
        fac[m] += 1
    return fac

fac = factor(M)

def search(i, ps, divisor):
    if M < N * divisor:
        return 1
    if i == len(ps):
        assert M % divisor == 0
        return divisor
    p, cnt = ps[i]
    dmax = 1
    for j in range(cnt+1):
        dmax = max(dmax, search(i+1, ps, divisor))
        divisor *= p
    return dmax

print(search(0, list(fac.items()), 1))

Submission status: Accepted

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: 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(reverse=True)
    return divisors

n, m = nm()

for divisor in make_divisors(m):
    if divisor <= m / n:
        print(divisor)
        exit()

Submission status: Accepted

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def 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(reverse=True)
        return divisors

    n, m = nm()

    for divisor in make_divisors(m):
        if divisor <= m / n:
            print(divisor)
            exit()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

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 = mi()
yakusu = make_divisors(M)
lim = M // N
ind = bisect.bisect_right(yakusu, lim)
ans = 1

print(yakusu[ind-1])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

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 = mi()
yakusu = make_divisors(M)
lim = M // N
ind = bisect.bisect_right(yakusu, lim)
ans = 1

for i in reversed(range(1, ind)):
    amari = M % yakusu[i]
    if not amari:
        ans = yakusu[i]
        break

print(ans)

Submission status: Accepted

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

for i in range(M//N, 0, -1):
    if M % i == 0:
        print(i)
        break

Submission status: Accepted

Solution code:
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 =map(int, input().split())
ans_sub = make_divisors(m)
for i in ans_sub:
  if i >= n:
    print(m//i)
    break

Submission status: Accepted

Solution code:
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

l = make_divisors(M)

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


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


n, m = map(int, readline().split())
if is_prime(m):
    if n == 1:
        print(m)
    else:
        print(1)
    exit()
for i in range(m // n, 0, -1):
    if m % i == 0:
        print(i)
        exit()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
divisors = set()
for i in range(1, int(m**.5)+1):
    if m % i == 0:
        divisors |= {i, m//i}
divisors = sorted(divisors)
for div in divisors:
    if n <= div:
        print(m//div)
        break

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

max_cand = m//n

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


divs = make_divisors(m)
divs.sort()

from bisect import bisect_right

index = bisect_right(divs, max_cand)

print(divs[index-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = list(map(int, input().split()))
divi = []

for i in range(1,int(M**0.5)+1):
    if M % i == 0:
        if i >= N:
            divi.append(i)
        if i != M//i:
            if M//i >= N:
                divi.append(M//i)

print(M//min(divi))

Submission status: Accepted

Solution code:
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 = map(int,input().split())
ans = 1
for i in make_divisors(m):
    if m // i >= n:
        ans = i
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
import math
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())
div = make_divisors(M)
ans = 0
for i in div:
    if M // i >= N:
        ans = max(ans,i)
print(ans)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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


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


d = divisors(M)

ans = 0

for i in d:
    if N * i <= M:
        ans = max(ans, i)

print(ans)

Submission status: Accepted

Solution code:
import io
import math

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

Submission status: Accepted

Solution code:
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

ans = 1
for v in make_divisors(m):
    if v <= m / n:
        ans = max(ans, v)
print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    def yakusuu(N):
        n = int(N**.5)+1
        res1 = []
        res2 = []
        for i in range(1, n):
            if N%i==0:
                res1.append(i)
                if N!=i**2:
                    res2.append(N//i)
        res2.reverse()
        return res1+res2
    a = yakusuu(m)
    a.sort(reverse=True)
    for i in a:
        if m//i >= n:
            print(i)
            break

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import sqrt

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

divisor = set([])
for i in range(1,int(sqrt(M))+1):
	if M % i == 0:
		if i <= int(M / N):
			divisor.add(i)
		if (M // i) <= int(M / N):
			divisor.add(M // i)

print(max(divisor))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N, M = [int(str) for str in input().strip().split()]

divs = []
for i in range(1, int(M**0.5) + 1):
    if M % i == 0:
        divs.append(i)
        if i**2 != M:
            divs.append(M // i)

divs.sort(reverse=True)

for div in divs:
    if M // div >= N:
        print(div)
        exit()

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
import heapq
import queue
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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

    table = set()
    i = 1
    while i * i <= M:
        if M % i == 0:
            table.add(i)
            table.add(M//i)
        i += 1
    
    res = 1
    for p in table:
        if p * N <= M:
            res = max(res, p)
    
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
div=[]
for i in range(1,int(M**(1/2)+1)):
  if M%i==0:
    div.append(i)
    if i!=M//i:
      div.append(M//i)
ans=[]
for j in range(len(div)):
  if M-(N-1)*div[j]>0:
    ans.append(div[j])
print(max(ans))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
# また答えが見つかってなければTrue
flag = True
for i in range(N, M//10 + 1):
    if M%i == 0:
        print(M//i)
        flag = False
        break
for i in range(9):
    if flag and M%(10 - i) == 0 and M//(10 - i) >= N:
        print(10 - i)
        flag = False
if flag:
    print(1)

Submission status: Accepted

Solution code:
def make_divisors(n):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    return div
n, m = map(int, input().split())
d = make_divisors(m)
d.sort()
for i in reversed(d):
    if i * n <= m:
        print(i)
        exit()

Submission status: Accepted

Solution code:
def acinput():
    return 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 sorted(divisors)


N,M=acinput()


for d in make_divisors(M):
    if d<=M/N:
        res=d
        

print(res)

Submission status: Accepted

Solution code:
N,M=map(int,input().split(' '))
l = [0]
for i in range(1,int(pow(M,0.5)+2)):
    if M%i==0:
        l.append(i)
        l.append(M//i)
if len(l)==1:
    print(0)
    exit()
l = sorted(list(set(l)))
for n,i in enumerate(l[1:]):
    if M/i<N:
        print(l[n])
        exit()
print(l[-1])