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

prime, i = set(), 1
while i * i <= M:
    if M % i == 0:
        prime.add(i)
        prime.add(M//i)
    i += 1

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

Submission status: Accepted

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

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

ans = 1
for d in ds:
    if d >= N:
        ans = max(ans, M//d)
print(ans)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
import heapq
import sys
# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 998244353
def mint(lis):
    return list(map(int, lis))

def bifind(arr_sorted, x):
    idx = bisect_left(arr_sorted, x)
    if idx == len(arr_sorted):
        return False
    if arr_sorted[idx] == x:
        return True
    else:
        return False
def getyaku(n):
    ret = []
    for i in range(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            ret.append(i)
            ret.append(n // i)

    return ret

def main():
    n, m = getList()
    ans = 0
    for yaku in getyaku(m):
        if m // yaku >= n:
            if ans < yaku:
                ans = yaku
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
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 fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
# 約数列挙
def find_divisor(n):
    divisors=[]
    for i in range(1, int(sqrt(n)) + 1):
        if n % i == 0:
            divisors.append(i)
            if i*i!=n:
                divisors.append(n // i)
    return divisors


def main():
    N,M=MI() ##Mの倍数
    ans = 1
    for d in find_divisor(M):
        if(M//d >= N):
            ans = max(ans, d)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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

res = 0
div = make_divisors(M)
for x in div:
  if M // x >= N: res = max(res, x)
print(res)

Submission status: Accepted

Solution code:
def main():
    def trial_division(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 = (int(i) for i in input().split())
    divs = trial_division(M)
    for d in divs:
        if N*d <= M:
            return print(d)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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


def calculate(n, m):
    res = 1
    for i in range(1, int(math.pow(m, 0.5))):
        if m % i != 0:
            continue

        j = m // i

        if i <= m // n:
            res = max(res, i)

        if j <= m // n:
            res = max(res, j)

    print(res)


calculate(N, M)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

##### dict の for文 #####
# for k, v in d.items():
#     print(k, v)

##### 進数の変換 #####
# bin_str = bin(i)[2:]
# oct_str = oct(i)
# hex_str = hex(i)

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

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

	ans = 1
	for i in range(1,M):
		if i > math.sqrt(M):
			break

		if M % i == 0:
			X = M // i
			I = i

			kouho = []
			if M % X == 0:
				tmp = M // X
				if tmp >= N:
					kouho.append(X)
			if M % I == 0:
				tmp = M // I
				if tmp >= N:
					kouho.append(I)

			if len(kouho) == 0:
				continue
			mmm = max(kouho)
			if ans < mmm:
				ans = mmm

	print(ans)



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# 2分検索のリバース
def bisect_left_reverse(a, x):
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok

def bisect_right_reverse(a, x):
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# 2分検索
# 存在しない場合: None 存在する場合: その値
def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    return None

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# N 個のボールを K グループに分ける場合のパターン数
def sunuke(N, K, mod=10**9+7):
	if N < K or K-1 < 0:
		return 0
	else:
		return combination(N-1, K-1, mod)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# dfs のサンプル
def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import math
import sys
MOD = 1000000007

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

if n == 1:
    print(m)
    sys.exit()

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

print(int(ans))

Submission status: Accepted

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===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 = ns()
    gcd = make_divisors(m)

    max_gcd = 1
    for d in gcd:
        if m // d >= n:
            max_gcd = max(max_gcd, d)

    print(max_gcd)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===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 = ns()
    gcd = make_divisors(m)

    max_gcd = 1
    for d in gcd:
        if m // d >= n:
            max_gcd = d
            break

    print(d)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

    st = {1, M}
    d = 2
    while d * d <= M:
        if M % d == 0:
            st.add(d)
            st.add(M // d)
        d += 1

    ans = 1
    for d in st:
        if d >= N:
            e = M // d
            ans = max(ans, e)
    print(ans)


if __name__ == '__main__':
    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 = (int(x) for x in input().split())
m = 0
for x in make_divisors(M):
    if M // x >= N:
        m = max(m,x)
print(m)

Submission status: Accepted

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

divisor_ls = make_divisors(m)

ans = 1
for divisor in divisor_ls:
    if m // divisor < n:
        break
    else:
        ans = divisor

print(ans)

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
def input(): return sys.stdin.readline().strip()


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

def main():
    N, M = map(int, input().split())
    divisors = make_divisors(M)
    while True:
        d = divisors.pop()
        if M >= N * d:
            print(d)
            return




if __name__ == "__main__":
    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)
    
    divisors.sort()
    return divisors

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

div = make_divisors(m)
ans = 0
for d in div:
    if d * n <= m:
        ans = max(ans, d)

print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
result = 1
for i in range(int(m**0.5), 0, -1):
    if m % i == 0:
        j = m // i
        if i >= n:
            result = max(result, j)
        elif j >= n:
            result = max(result, i)
print(result)

Submission status: Accepted

Solution code:
from math import floor
N,M=map(int,input().split())
p= floor(M**0.5)
kumi=[]

for i in range(1,p+1):
  if M%i==0:
    kumi.append((i,M//i))
    
ans=1
for pair in kumi:
  if pair[0]>=N:
    ans = max(ans,pair[1])
  if pair[1]>=N:
    ans = max(ans,pair[0])
print(ans)

Submission status: Accepted

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

    n,m=map(int,input().split())
    c = make_divisors(m)
    for i in c:
        if n>m//i:
            continue
        else:
            print(i)
            break
        
if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
div = []
for i in range(1,int(m**0.5)+1):
    if m%i == 0:
        div.append(i)
        div.append(m//i)
div.sort(reverse=True)
for x in div:
    if m//x >= n:
        print(x)
        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:
        x = m//i
        if x >= n:
            ans = max(ans,i)
        if i >= n:
            ans = max(ans,x)
print(ans)

Submission status: Accepted

Solution code:
# n: 数列の項数　m: 数列の和
# d=公約数とすると、数列は全項がdの倍数である
# よって数列の和もdの倍数である
# ゆえに、dはmの約数である
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


d = divisor(m)
ans = 0
for i in d:
    # i: mの約数。数列の公約数でもある。
    # 公約数 * nが、mを超えない範囲で最大の公約数を求める
    if i * n <= m:
        ans = max(i, ans)

print(ans)

Submission status: Accepted

Solution code:
# D - Partition
import bisect
N, M = map(int, input().split())

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

d = make_divisors(M)
print(M//d[bisect.bisect_left(d, N)])

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().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

n,m = inpl()
for i in make_divisors(m):
    if i < n:
        continue
    print(m//i)
    break

Submission status: Accepted

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

from math import floor
n,m=map(int,input().split())
n_max=floor(m/n)
d=create_divisors(m)
for di in d:
  if di<=n_max:
    print(di)
    exit(0)

Submission status: Accepted

Solution code:
def 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())
ans = 0
nums = divisors(m)
nums.sort()
num = nums.pop(0)
while num * n <= m:
    if (m - num * n) % num == 0:
        ans = num
    if nums == []:
        break
    num = nums.pop(0)
print(ans)

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    f = [1, m]
    i = 2
    while i * i <= m:
        if m % i == 0:
            f.append(i)
            if m != i * i:
                f.append(m // i)
        i += 1
    f.sort()
    answer = 0
    for ff in f:
        if n <= ff:
            answer = m // ff
            break
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 1
for x in range(1, 10 ** 5 + 10):
    if M % x == 0:
        if N * x <= M:
            ans = max(ans, x)
        if N * (M // x) <= M:
            ans = max(ans, M // x)

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:
    y=m//i
    if m//i>=n and ans<i:
      ans=i
    if m//y>=n and ans<y:
      ans=y
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())
print(max([x for x in make_divisors(M) if x <= M // N]))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
if N==1:
    nmax=M
else:
    nmax = 1
    for i in range(2,int(M**0.5)+1):
        if M%i==0 and M//i>=N:
            nmax = max(nmax,i)
        if M%i==0 and i>=N:
            nmax = max(nmax,M//i)
print(nmax)

Submission status: Accepted

Solution code:
import sys

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


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

    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

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

    print(res)




if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

s = M//N
for i in reversed(range(1,s+1)):
  if M%i == 0:
    ans = i
    break
print(ans)

Submission status: Accepted

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

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

#  nの約数をO(root(n))で全列挙、
# sortするなら O(root(n) * root(n)log(root(n))) --> O(n * log(n))
def make_divisors(n):
    import math
    divisors = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0: #割り切れるとき
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    divisors.sort(reverse = True)
    return divisors

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
# 素因数分解
from collections import defaultdict


def divide(n):  # unsort
    ans = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            ans.append(i)
            if n // i == i:
                continue
            ans.append(n // i)
    return ans


ans = 1
soin = divide(m)
soin.sort(reverse=True)
for num in soin:
    if num * n <= m:
        ans = num
        break

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,m=mp()
for i in range(m//n,0,-1):
    s,a=divmod(m,i)
    if a%s==0:
        print(i)
        exit()

Submission status: Accepted

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

#nの約数列挙
def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    return ass #sortされていない

div = divisor(M)
ans = 0
for d in div:
    if M//d >= N:
        ans = max(ans,d)
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

sq = math.sqrt(M)
sq = math.floor(sq)


ans = 1
for i in range(1,sq+2):
  if M % i == 0:
    if i * N <= M:
      ans = max(i,ans)
    if M / i * N <= M:
      ans = max(M // i,ans)
if N == 1:
  print(int(M))
else:
  print(int(ans))

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

Submission status: Accepted

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

ans = 0
for i in range(1, int(m ** 0.5) + 1)[::-1]:
    if (m % i == 0):
        if m / i >= n:
            ans = max(ans, i)
        if i >= n:
            ans = max(ans, m // i)
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


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


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

    divisors = make_divisors(M)
    ans = 1
    for d in divisors:
        if M // d >= N:
            if ans < d:
                ans = d

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(n=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(n+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, n+1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## const ##
MOD=10**9+7
## libs ##
import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
    n, m = MII()
    divs = enumerate_divs(m)
    ans = []
    h = m/n
    for i,j in divs:
        if i <= h:
            ans.append(i)
        if j <= h:
            ans.append(j)
    print(max(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,M=list(map(int,input().split()))
def div(N):
   l=[]
   for i in range(1,int(N**0.5)+1):
      if N%i==0:
         l.append(i)
         if i != N//i:
            l.append(N//i)
   l.sort()
   return l
l = div(M)
ans=-1
for i in l:
   if M//i>=N:
      ans+=1
   else:
      break
print(l[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
li = make_divisors(m) 
#print(make_divisors(m)) [1, 14, 2, 7]
ans = 1
for l in li:
    if l>ans and l*n <= m:
        ans = l
print(ans)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m = na()

if n == 1:
    print(m)
    exit()

i = 1
ans = 1
while i * i <= m:
    if m % i == 0:
        if m // i >= n:
            ans = max(ans, i)
        if i >= n:
            ans = max(ans, m // i)
    i += 1

print(ans)

Submission status: Accepted

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

# M = a x bの形に分解する
pair = []
for i in range(1, int(math.sqrt(M))+1):
    if M % i == 0:
        pair.append((i, M // i))

ans = 1
for a, b in pair:
    if b >= N:
        ans = max(ans, a)
    if a >= N:
        ans = max(ans, b)

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

div = make_divisors(m)

for i in div:
    if i * n <= m:
        ans = i
    else:
        break

print(ans)