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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, M = in_nn()

    ans = 1
    inf = M // N + 1
    for i in range(inf, 1, -1):
        if i * N <= M and M % i == 0:
            ans = i
            break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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


N, M = map(int, input().split())
divs = filter(lambda x: x <= M // N, enum_divisors(M))
print(max(divs))

Submission status: Accepted

Solution code:
import math
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
N,M=map(int,input().split())
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
if N==1:
  print(M)
else:
  ans=0
  a=M//N
  v=make_divisors(M)
  for i in range(a,0,-1):
    if M%i==0:
      print(i)
      break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
d = []
i = 1
while i ** 2 <= m:
    if m % i == 0:
        d.append(i)
        j = m // i
        if j != i:
            d.append(j)
    i += 1
d.sort(reverse=True)
for t in d:
    if m // t >= n:
        print(t)
        exit()

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:continue
    if m//i>=n:
        ans = max(i,ans)
    if i>=n:
        ans = max(m//i,ans)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

n,m = map(int,input().split())
ans = 0
tmp = int(m/n)
for i in range(1,int(np.sqrt(m)+1)):
    if m%i == 0:
        if (ans < i) and(i <= tmp):
            ans = i
        tmp2 = m//i
        if (ans < tmp2) and(tmp2 <= tmp):
            ans = tmp2
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
n,m=mii()

def mdiv(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
#print(mdiv(m))

ans=0
for i in mdiv(m):
    if i<=m//n:
        ans=max(i,ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def __gcd__(m,n):
    x,y=max(m,n),min(m,n)
    if x%y==0:
        return y
    else:
        while x%y!=0:
            z=x%y
            x,y=y,z
        else:
            return z
        
from functools import reduce
def GCD(*X):
    return reduce(__gcd__,X)

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

Q=M//N
R=M%N

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

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:continue
    if m//i>=n:
        ans = max(i,ans)
    if i>=n:
        ans = max(m//i,ans)

print(ans)

Submission status: Accepted

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


def make_divisors(num):
    divisors = []
    for i in range(1, m+1):
        if i * i > m:
            break
        if m % i == 0:
            divisors.append(i)
            divisors.append(m // i)
    return divisors

div = make_divisors(num=m)
div.sort()
ans = 1
for x in div:
    if x*n <= m:
        ans = x
print(ans)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def factorization(n):
    factor_list = []
    if n < 1:
        return factor_list
    limit = int(math.sqrt(n))+1
    for i in range(1, limit):
        if n % i == 0:
            factor_list.append(i)
            if not n == i**2:
                factor_list.append(n//i)
    factor_list.sort()
    return factor_list

factor = factorization(M)


ans = 1
for f in factor:
    if N * f <= M and f > ans:
        ans = f
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    N, M = list(map(int, input().split()))
    factors = []
    i = 1
    while i <= M**(1/2):
        if M%i==0:
            factors.append(i)
            factors.append(M//i)
        i += 1
    factors = sorted(factors, reverse=True)
    #print(factors)
    for fac in factors:
        if N*fac <= M and (M-N*fac)%fac == 0:
            print(fac)
            break


if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SMI(): return input().split()
def SLI(): return list(input())
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    N, M = MI()

    ans = 1
    for i in range(1, int(pow(M, 0.5))+1):
        if M % i: continue
        if N * i <= M: ans = max(ans, i)
        if N * (M // i) <= M: ans = max(ans, M//i)
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
if M==1: print(1);exit()
if N==1: print(M); exit()
ans = 1
for i in range(2,int(M**(1/2)+2)):
    if M%i==0:
        p = M//i
        if p <=M/N:
            ans = max(p,ans) 
        if i<=M/N:
            ans = max(ans,i)
print(ans)

Submission status: Accepted

Solution code:
import bisect

def divisor(n):
    lower, upper = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower.append(i)
            if i != n // i:
                upper.append(n // i)
        i += 1
    return lower + upper[::-1]

n, m = map(int, input().split())
M = divisor(m)
if n not in M:
    x = bisect.bisect_left(M, n)
    ans = (m // M[x])
else:
    ans = m // n
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
factors = [1, m]
sqrt = round(m ** 0.5 + 0.5)
for i in range(2, sqrt + 1):
    if not m % i:
        factors.append(i)
        factors.append(m // i)
factors = sorted(factors)
def search(l):
    for i in l:
        if i >= n:
            return m // i
print(search(factors))

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc112


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


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

    for x in reversed(xs):
        if M // x >= N:
            return x


print(main())

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

N, M = map(int, input().split())
l = make_divisors(M)
# mの約数
res = 1
# 全ての約数において、kと仮定する
for k in l:
    x = M // k
    # この際、Mをkで除した数列bがN以上であるかを判定する
    if x >= N:
        res = max(res, k)
print(res)

Submission status: Accepted

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

maxi = 1
for i in range(int(M**0.5), 0, -1):
    if M % i != 0:
        continue
    if M//i >= N:
        maxi = max(maxi, i)
    if i >= N:
        maxi = max(maxi, M//i)

print(maxi)

Submission status: Accepted

Solution code:
# これはエスパーですがMが素数ならNが何であってもできなさそう？未証明
# で 合成数のみっぽいので定石的に素因数分解すると
# 各項に因数をどれだけ割り振れるかみたいになる？
# -> サンプル1をみるとならなそう
# 最大公約数をgcdとすると、a*gcd*(N-1)+b*gcd = M となるのが都合よさそう こうなると右辺もgcdで割れるのでやはり約数のどれかになりそう
n, m = map(int, input().split())


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

    upper_divisors.reverse()
    return lower_divisors + upper_divisors


if m % n == 0:
    print(m // n)
    exit()
else:
    x = m // n
    divisors = make_divisors(m)[::-1]
    for d in divisors:
        if d <= x:
            print(d)
            exit()

Submission status: Accepted

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

if m % n == 0:
    print(m // n)
    sys.exit()


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


div = make_divisors(m)
div = [x for x in div if x <= m // n]

print(max(div))

Submission status: Accepted

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

Submission status: Accepted

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

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

    res.sort()
    return res

d = divisor(M)
ans = 1
for x in d:
    m = M
    m -= x * (N - 1)
    if m > 0 and m % x == 0:
        ans = x

print(ans)

Submission status: Accepted

Solution code:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


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

mlis=make_divisors(m)

I=1
for i in mlis:
    if m<i*n:
        break
    else:
        I=i
    
print(I)

Submission status: Accepted

Solution code:
import bisect

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

n_facs_s = []
n_facs_l = []
for i in range(1, int(-(-m**0.5//1))+1):
    if m%i == 0:
        n_facs_s.append(i)
        n_facs_l.append(m//i)


n_faces = n_facs_s + n_facs_l[::-1]
ind = bisect.bisect_right(n_faces, n)
if n_faces[ind-1] == n:
    ind-=1
print(m//n_faces[ind])

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:
        x = m//i
        if x>=n:
            ans = max(ans,i)
        if i>=n:
            ans = max(ans,x)
        
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    n, m = map(int, readline().split())
    div = []
    for i in range(1, int(m**0.5)+1): 
        if m%i == 0:
            div.append(i)
            div.append(m//i)

    ans = 0
    for d in div:
        if m//n >= d:    
            ans = max(ans, d)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

div = M
for i in range(1, int(math.sqrt(M))+1):
    if M % i:
        continue
    i2 = M // i
    if i >= N:
        div = min(div, i)
    if i2 >= N:
        div = min(div, i2)

print(M//div)

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

a,b = map(int, input().split())
l = make_divisors(b)
l.sort(reverse=False)
res = 1
#print(l)
for x in l:
    if x <= b//a:
        res = max(x, res)
print(res)

Submission status: Accepted

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(input = sys.stdin.readline):
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())

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



if __name__ == '__main__':
    main()

Submission status: Accepted

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
Mdiv = make_divisors(M)
out = 1
for k in Mdiv:
    A = M//k
    if A>=N:
        out = max(out,k)
print(out)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
s=set()
for i in range(1,int(m**0.5)+1):
    if m%i==0:
        s.add(i)
        s.add(m//i)
s=sorted(s,reverse=True)
for i in range(len(s)):
    if s[i]<n:
        print(m//s[i-1])
        break
else:print(m)

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 i in make_divisors(m):
    if i>=n:
        ans=max(ans,m//i)
print(ans)

Submission status: Accepted

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

ans=M//N
while True:
    if (M-(N-1)*ans)%ans==0:
        break
    ans-=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int, readline().split()))

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

d = 1
ds = []
while d ** 2 <= M:
    if M % d == 0:
        ds.append(d)
        ds.append(M // d)
    d += 1
ds.sort(reverse=True)
for d in ds:
    if N * d <= M:
        print(d)
        break

Submission status: Accepted

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

if N == 1:
    print(M)
else:
    d = 1
    ds = []
    while d ** 2 <= M:
        if M % d == 0:
            ds.append(d)
            ds.append(M//d)
        d += 1
    ds.sort(reverse=True)
    for d in ds:
        if N * d <= M:
            print(d)
            break

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

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

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
from heapq import heapify, heappop, heappush


def solve():
    N, M = MI()

    ans = 1
    for i in range(1, int(pow(M, 0.5))+1):
        if M % i: continue
        j = M // i

        if i * N <= M: ans = max(ans, i)
        if j * N <= M: ans = max(ans, j)
    print(ans)




if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

import math
# isprime, prime_division

def isprime(x):
    q = int(math.sqrt(x))  # int() rounds to zero
    for i in range(2,q+1):   # upto q
        if x%i == 0:
            return False
    return True

def prime_division(x):
    q = int(math.sqrt(x))
    a = []
    for i in range(2,q+1):
        ex = 0
        while x%i == 0:
            ex += 1
            x //= i
        if ex>0:
            a.append([i,ex])
    if x>q:
        a.append([x,1])
    return a

def prime_division2(x):
    q = int(math.sqrt(x))
    h = {}
    for i in range(2,q+1):
        ex = 0
        while x%i == 0:
            ex += 1
            x //= i
        if ex>0:
            h[i] = ex
    if x>q:
        h[x] = 1
    return h

def divisorlist(z): # z : output of prime_division
    if len(z)==1:
        return [z[0][0]**i for i in range(z[0][1]+1)]
    y = divisorlist(z[1:])
    s = []
    for i in range(z[0][1]+1):
        for j in y:
            s.append((z[0][0]**i)*j)
    return s

n,m = inm()
if m==1:
    print(1)
    exit()
#ls = prime_division(m)
#ddprint(ls)
ps = divisorlist(prime_division(m))
#ddprint(ps)
ps2 = [x for x in ps if x<=m//n]
print(max(ps2))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return upper_divisors + lower_divisors[::-1]
m_divisor = make_divisors(m)
for i in m_divisor:
    if i <= m / 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(reverse = True)
    return divisors
  
n, m = list(map(int, input().split()))
div = make_divisors(m)
for i in div:
  if m / i >= n:
    print(i)
    quit()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

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

# Mの約数Pのうち、M // P >= Nとなるものの最大値

ans = 0
for i in range(1,int(M ** 0.5) + 1):
  if M % i == 0:
    p = M // i
    if i >= N:
      if ans < p:
        ans = p
    if p >= N:
      if ans < i:
        ans = i

print(ans)

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n,m=n1()

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)
i=bisect_right(div,m//n)
print(div[i-1])

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

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

# Mの約数Pのうち、M // P >= Nとなるものの最大値

ans = 0
for i in range(1,int(M ** 0.5) + 1):
  if M % i == 0:
    p = M // i
    if i >= N:
      if ans < p:
        ans = p
    if p >= N:
      if ans < i:
        ans = i

print(ans)

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,M = map(int,input().split())

ans = 0
div1,div2 = [],[]
for m in range(1,int(M**.5)+1):
    if M%m == 0:
        div1.append(m)

for d in div1:
    if M%d == 0:
        div2.append(M//d)

div3 = div1+div2
div3.sort()
for d in div3:
    if d <= M//N:
        ans = d

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print (ans)

Submission status: Accepted

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

for i in range(1,int(m**0.5)+1):
    if m%i==0:
        if i<=m//n:
            tmp=i
        if i>=n:
            tmp=m//i
            print(tmp)
            sys.exit()
print(tmp)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
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

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

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,M = IL()

l =make_divisors(M)
l.sort()

while True:
  ans = l.pop()
  if M//ans >= N:
    print(ans)
    exit()

Submission status: Accepted

Solution code:
def divisor(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()
    return d

n, m = map(int, input().split())
d = divisor(m)
for i in range(len(d)-1, -1, -1):
    if d[i] <= m/n:
        print(d[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()
    return divisors
divs = make_divisors(M)
ans = []
for i in divs:
    if i * N <= M:
        ans.append(i)
print(max(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:
        continue

    j = M // i
    if i * N <= M:
        ans = max(ans, i)
    if j * N <= M:
        ans = max(ans, j)

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

tab = divisor(M)
ans = []
for i in tab:
    j = M // i
    if j >= N:
        ans += [i]
print(max(ans))

Submission status: Accepted

Solution code:
def solve(n, m):
    ret = 1
    for i in range(1, int(m ** 0.5) + 1):
        if m % i != 0:
            continue
        c = m // i
        if n * c <= m:
            return c
        elif n * i <= m:
            ret = i
    return ret


def main():
    n, m = map(int, input().split())
    print(solve(n, m))


if __name__ == "__main__":
    main()
    # for n in range(1, 500):
    #     for m in range(n, 1000):
    #         i = solve(n, m)
    #         assert m % i == 0, (n, m, i)
    #         assert n*i <= m, (n, m, i)

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,m=map(int,readline().split())
    d=make_divisors(m)
    l=m//n
    for v in d:
        if v<=l:
            print(v)
            break

def make_divisors(n):
    if n==1:
        divisors=[1]
        return divisors
    else:
        divisors=[]
        for i in range(1,n):
            if i*i>n:
                break
            if n%i==0:
                divisors.append(i)
                if i!=n//i:
                    divisors.append(n//i)

        divisors.sort(reverse=True)
        return divisors

if __name__=="__main__":
    main()