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:
#!/usr/bin/env python3

def main():
    n, m = map(int, input().split())
    dm = dividor_of(m)
    res = 1
    for d in dm:
        if d <= m / n:
            res = d
    print(res)

def dividor_of(m):
    res = set()
    for i in range(1, 10 ** 5):
        if m % i == 0:
            res.add(i)
            res.add(m // i)
        if i ** 2 >= m:
            return sorted(list(res))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

import math

divisor=[]
for i in range(1, math.ceil(math.sqrt(M))+1):
    if M%i==0:
        divisor.append(i)
#print(divisor)

divisor+=[M//val for val in reversed(divisor)]
#print(divisor)
for val in divisor:
    if val>=N:
        print(M//val)
        break

Submission status: Accepted

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

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

divisors = make_divisors(m)

for d in divisors:
    if m >= n*d and ans < d:
        ans = d
print(ans)

Submission status: Accepted

Solution code:

import math


def divisor(x):
    d = {}
    for i in range(1, math.ceil(math.sqrt(x)) + 1):
        q, r = divmod(x, i)
        if r == 0:
            d[i] = 1
            if q != i:
                d[q] = 1
    d = list(d.keys())
    d.sort()
    return d
    


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

    # Mの約数を求める
    d = divisor(m)
    nd = len(d)

    # 二分探索で条件を満たすdを求める
    l = 0
    r = nd - 1
    while l <= r:
        mid = (l + r) // 2
        if n * d[mid] <= m:
            l = mid + 1
        else:
            r = mid - 1
    print(d[l - 1])


submit()

Submission status: Accepted

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

def main():
    N, M = map(int, input().split())
    MN = M/N
    divisor = make_divisors(M)
    max_gcd = 0
    for d in divisor:
        if (d<=MN) and (d>=max_gcd):
            max_gcd = d
    print(max_gcd)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
N,M=map(int,input().split())
l=[]
for i in range(1,int(math.sqrt(M))+1):
  if M%i==0:
    l.append(i)
    if i!=M//i:
      l.append(M//i)
l=sorted(l,reverse=False)
while l:
  v=l.pop(-1)
  tot=M//v
  if tot<N:
    pass
  else:
    print(v)
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math

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

divisor_set=set()
for i in range(1,int(math.sqrt(M)+1)):
  if M%i==0:
    divisor_set.add(i)
    divisor_set.add(M//i)
#print(divisor_set)

divisor_list=list(divisor_set)
divisor_list.sort()

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

Submission status: Accepted

Solution code:
#約数
def divisor(x):
    ret = []
    for i in range(1,int(x ** 0.5) + 1):
        if x % i == 0:
            ret.append(i)
            ret.append(x // i)
    return list(set(ret))

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

div = divisor(m)
div.sort(reverse=True)

for i in div:
    if m / i >= n:
        print(i)
        exit()

Submission status: Accepted

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

def divisors(n):
    div = []
    i = 1
    while(i * i <= n):
        if n % i == 0:
            div.append(i)
            if i * i != n:
                div.append(n // i)
        i += 1
    return div


cand = sorted(divisors(m), reverse=True)

result = 1
i = 0
for i in range(len(cand)):
    if m // cand[i] >= n:
        result = cand[i]
        break

print(result)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
m_root=int(m**0.5)
div_l=[]
ans=0

for i in range(1,m_root + 1):
    if m%i == 0:
        div_l.append(i)
        div_l.append(m//i)

if m//n in div_l:
    ans = m//n
else:
    div_l.append(m//n)
    div_l.sort()
    ans = div_l[div_l.index(m//n) - 1]
print(ans)

Submission status: Accepted

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

base=M//N
li=[]


for i in range(1,int(pow(M,1/2))+1):
    if i<=base and M%i==0:
        li.append(i)
    if M%i==0 and M//i<=base:
        li.append(M//i)

print(max(li))

Submission status: Accepted

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

upper_bound = int(math.sqrt(M))

qmin = M
for q in range(1, upper_bound + 1):
    if M % q != 0:  continue
    
    q2 = M // q
    if q >= N:
        qmin = q
        break
    elif q2 < N:
        break
    else: # q2 >= N
        qmin = q2

print(M // qmin)

Submission status: Accepted

Solution code:
import bisect
def factor(N):
    arr=[]
    for i in range(1,int(N**0.5)+1):
        if(N%i==0):
            arr.append(i)
            if(N//i!=i):
                arr.append(N//i)
    return arr

N,M=map(int,input().split())
li=sorted(factor(M))
res=1
for i in li:
    if(i>M//N):
        break
    if(M//i>=N):
        res=i
print(res)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
k = m//n
ans = 1
i = 1
while i**2 <= m:
	if m%i==0:
		j = m//i
		if j <= k:
			print(j);exit()
		if i <= k:
			ans = max(ans,i)
	i += 1
print(ans)

Submission status: Accepted

Solution code:
def divisor(i):
    s = []
    for j in range(1, int(i ** (1 / 2)) + 1):
        if i % j == 0:
            s.append(i // j)
            s.append(j)
    return sorted(set(s))

n, m = map(int, input().split())
l = m // n
s = divisor(m)
s.reverse()
for i in s:
    if m % i == 0 and l >= i:
        ans = i
        break
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
i = 1
lis = []
while M//i>=N and i<=M**0.5:
  if M % i == 0:
    lis.append(i)
  i += 1
for l in lis[::-1]:
  ans = M//l
  if M//ans>=N:
    lis.append(ans)
print(lis[-1])

Submission status: Accepted

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

# Mの約数を列挙
sup = int(M**0.5) + 1
divs_left = []
divs_right = []
for i in range(1, sup+1):
  if M%i == 0:
    divs_left.append(i)
    divs_right.append(M//i)

divs = divs_right + divs_left[::-1]
for d in divs:
  if M//d >= N:
    print(d)
    quit()

Submission status: Accepted

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

divisors = set()

for i in range(1, int(m**0.5)+1):
    if m % i == 0:
        divisors.add(i)
        divisors.add(m//i)

divisors = sorted(list(divisors))
ans = 1

for d in divisors:
    if d <= m/n:
        ans = max(ans, d)
    else:
        break

print(ans)

Submission status: Accepted

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

from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N,M=map(int,readline().split())

    d=make_divisors(M)
    for i in range(len(d)):
        if d[i]-N>=0:
            print(M//d[i])
            break

if __name__=="__main__":
    main()

Submission status: Accepted

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

l.sort()
for i in range(len(l)-1,-1,-1):
    if l[i] <= m//n:
        print(l[i])
        exit()

Submission status: Accepted

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

i=1
ans=0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split(' '))

ret = 1
for i in range(1, int(M**0.5)+1):
    if M % i == 0 and i * N <= M:
        ret = max(ret, i)

        j = M//i
        if M % j == 0 and j * N <= M:
            ret = max(ret, j)

        # exit()
print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
divisors = []
for i in range(1,int(M**.5)+1):
    if M%i == 0:
        divisors.append(i)
        if M//i != i:
            divisors.append(M//i)
ans = 1
for x in divisors:
    if x <= M//N:
        ans = max(ans,x)
print(ans)

Submission status: Accepted

Solution code:
import bisect

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

vector = []

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

vector.sort()

bottom = M//N
index = bisect.bisect_right(vector, bottom)

ans = vector[index-1]
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from math import floor

def main():
  n, m = map(int, input().split())
  divisors = []
  for i in list(range(1, floor(m**0.5)+1))[::-1]:
    if m%i == 0:
      divisors.insert(0, i)    
      if m//i != i:
        divisors.append(m//i)
  
  for divisor in divisors[::-1]:
    if m//divisor >= n:
      print(divisor)
      return
    
if __name__=='__main__':
  main()

Submission status: Accepted

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

def divisor_all(n): # 約数全列挙
    l = [1,n]
    for i in range(2,int(pow(n,1/2))+1):
        if n % i == 0:
            if i == n//i:
                l.append(i)
            else:
                l.append(i)
                l.append(n//i)
    l.sort()
    return l # list

DM = list(reversed(divisor_all(M)))
ans = 1
for d in DM:
    r = M//d
    if r < N:
        continue
    else:
        ans = d
        break
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt

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


def fact(x):
	ret = []
	for i in range(1, int(sqrt(x)) + 1):
		if x % i == 0:
			ret.append(i)
			ret.append(x // i)

	return ret


fct = fact(m)
ans = 1
for e in fct:
	if e <= m / n:
		ans = max(ans, e)

print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
r=m//n
if r>=10**7:
  for i in range(n,r):
    if m%i==0:
      print(m//i)
      break
else:
  for i in range(r):
    if m%(r-i)==0 and m//(r-i)>=n:
      print(r-i)
      break

Submission status: Accepted

Solution code:
# 数列aの最小値min_aの最大値はM//N
# 他の要素がmin_aの倍数であれば、min_aが最大公約数となる
# すなわち、(M-min_a)をmin_aで割った余りが0でありかつ、商がN-1以上
 
N, M = map(int, input().split())
 
for i in range(M//N, 0, -1):
    r, q = divmod((M - i), i)
    if r >= N - 1 and q == 0:
        break
print(i)

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)

    return divisors

l=make_divisors(M)
l.sort()
ans=0
for i in range(len(l)):
    if (l[i]*N)<=M:
        ans=max(l[i],ans)
print(ans)

Submission status: Accepted

Solution code:
# Problem D - Partition

# 公約数を列挙する関数
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

# input process
N, M = map(int, input().split())
common_divisors = make_divisors(M)

# initialization
max_cd = 1

for c in common_divisors:
    if c*N<=M:
        max_cd = max(max_cd, c)

print(max_cd)

Submission status: Accepted

Solution code:
# import bisect
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)
ans=1
for i in range(len(div)):
    if(div[i]>m/n):
        break
    ans=max(div[i],ans)
print(ans)

Submission status: Accepted

Solution code:
N, M = (int(i) for i in 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
  
div = make_divisors(M)

for d in div:
    if int(M/d) >= N:
        print(d)
        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
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 input(): return sys.stdin.readline().strip()
def INT(): return int(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()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

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

yakusu = divisor(M)
yakusu.sort(reverse=True)

ans = 0
for y in yakusu:
    if y <=  M / N:
        ans = y
        break
print(ans)

Submission status: Accepted

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

max_check = (m**(1/2))//1
ans = 0
for i in range(1, int(max_check)+1):
    if m % i == 0:
        josuu = i
        shou = int(m//i)
        if josuu >= n:
            ans = max(ans, shou)
        if shou >= n:
            ans = max(ans, josuu)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 1

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

Submission status: Accepted

Solution code:
# coding: utf-8
N, M = map(int, input().split())
ans = 1
for d in range(1, int(M**0.5)+1):
    if M % d == 0 and d <= M / N:
        ans = max(ans, d)
        if M // d <= M // N:
            ans = max(ans, M//d)
print(ans)

Submission status: Accepted

Solution code:
import bisect
N,M = map(int,input().split())
maxa = 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
mdiv = sorted(make_divisors(M))
ans = mdiv[bisect.bisect_right(mdiv,maxa)-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(reverse=True)
    return divisors

def main():
    N, M = map(int, input().split())
    d = make_divisors(M)
    for i in d:
        if M // i >= N:
            return i
print(main())

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    d = []
    i = 1
    while i * i <= M:
        if M % i == 0:
            d.append(i)
            if M // i != i:
                d.append(M // i)
        i += 1
    d.sort(reverse=True)
    for i in d:
        if M // i >= N:
            print(i)
            return
    print(1)
main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

a = (m//n)

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

Submission status: Accepted

Solution code:
def main():
    N, M = (int(i) for i in input().split())

    def trial_division(n):
        """
        nの約数のリストをO(sqrt(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)
        return divs
    divs = trial_division(M)
    ans = 0
    for d in divs:
        if d*N <= M:
            ans = max(ans, d)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
def divisor(m): 
    i = 1
    table = []
    while i * i <= m:
        if m%i == 0:
            table.append(i)
            table.append(m//i)
        i += 1
    table = list(set(table))
    return table
L = divisor(m)
ans = 0
for l in L:
  if l <= m/n:
    ans = max(ans, l)
print(ans)

Submission status: Accepted

Solution code:
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)
    ass.sort()
    return ass #sortされていない

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

A = divisor(M)

b = M//N

ans = A[0]

for a in A:
    if a <= b:
        ans = a
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

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

n, m = na()
div = []
for i in range(1, int(m**0.5)+1):
    if m % i == 0:
        j = m // i
        #i * j = n
        if i >= n:
            div.append(j)
        if j >= n:
            div.append(i)

print(max(div))

Submission status: Accepted

Solution code:
import math
n, m = map(int, input().split())
if m%2 == 0:
    divisor = [1, 2, m//2, m]
else:
    divisor = [1, m]
for i in range(3, int(math.sqrt(m))+1):
    if m%i == 0:
        divisor.append(i)
        divisor.append(m//i)
divisor = sorted(divisor, reverse=True)
a = m//n
for i in divisor:
    if i > a:
        continue
    if (m-(m//i*i))%i == 0:
        break
print(i)

Submission status: Accepted

Solution code:
#112_D
N,M=map(int,input().split())
#M//N以下のMの約数の最大
divisors=[]
for i in range(1,int(M**.5)+1):
    if M%i==0:
        divisors.append(i)
        if i!=(M//i):
            divisors.append(M//i)
Ans=1
for x in sorted(divisors):
    if M//N>=x:
        Ans=x
    else:
        break
print(Ans)

Submission status: Accepted

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

num=m//n
ans=1
for i in range(1,int(m**0.5)+1):
    if m%i==0:
        Num=m//i
        if Num <= num and ans < Num:
            ans = Num

        if i<=num and ans<i:
            ans=i
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())
a=make_divisors(m)
ans=0
for i in a:
    if i<=m/n and i>ans:
        ans=i
print(ans)
#解説参照済み

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n,m = map(int,input().split())
INF = m
ans = INF
# どうしてTLE？？O(root(m))で10**4だからOKでは？ m ** 1/2だとm /2 になる
for i in range(1,int(m**(1/2)) + 1):
    if m % i == 0:
        # i,m//iのうち、n 以上でmaxなものをansに入れる
        if i >= n: ans = min(ans,i)
        if m//i >= n: ans = min(ans,m//i)
print(m//ans)

Submission status: Accepted

Solution code:
def main():
    def trial_division(n):
        """
        nの約数のリストをO(sqrt(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)
        return divs
    N, M = (int(i) for i in input().split())
    ans = 0
    divs = trial_division(M)
    for d in divs:
        if M >= N*d:
            ans = max(ans, d)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from itertools import combinations as combi
input = sys.stdin.readline
N, M = map(int, input().split())
if N == 1:
  print(M)
  exit(0)
i = 2
res = 1
while i * i <= M:
  t = 1
  if M % i == 0 and (M // i >= N):
    res = max(res, i)
    t = M // i
  if M % t == 0 and (M // t >= N):
    res = max(res, t)
  i += 1
print(res)

Submission status: Accepted

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

P = []
for k in range(1,math.floor(math.sqrt(M))+1):
    if M % k == 0:
        P.append(k)
        P.append(M//k)
ans = 1
for e in P:
    if e*N <= M:
        ans = max(ans,e)
print(ans)

Submission status: Accepted

Solution code:
# Problem - D Partition

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())
gcd_max = 0 # 最大公約数の最大値
a_list = [[0]*N]
# 約数の列挙
divisor_list = make_divisors(M)

for d in divisor_list:
    check_sum = N * d
    if check_sum<=M:
        gcd_max = max(gcd_max, d)

print(gcd_max)

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

div = make_divisors(M)

ans = 0
for x in div:
    if x*N <= M:
        ans = max(ans, x)

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

l = make_divisors(m)
for c in l:
    if m//c >= n:
        print(c)
        exit()

Submission status: Accepted

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

fact = []
for i in range(1, int(m**0.5)):
    if m%i==0:
        fact.append(i)
        fact.append(m//i)
fact.sort()

ans = 1
for i in fact:
    if n*i<=m: ans = i
print(ans)

Submission status: Accepted

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

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()
    ans = 0
    for d in find_divisor(M):
        if N<=M//d:
            ans = max(ans,d)
    print(ans)
    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    maxGCD = 1
    for gcd in range(1, M):
        if gcd * gcd > M: break
        else:
            if M % gcd == 0:
                other = M // gcd
                if gcd >= N: maxGCD = max(other, maxGCD)
                if other >= N: maxGCD = max(gcd, maxGCD)
    print(maxGCD)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
import fractions
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15

def getyaku(n):
    res = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            res.append(i)
            res.append(n // i)

    return(sorted(list(set(res))))

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

def main():
    n,m = getlist()
    arr = getyaku(m)
    for num in arr:
        if num >= n:
            print(m//num)
            return
    print(1)
    # print(arr)
    return

if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Submission status: Accepted

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

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

Submission status: Accepted

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

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

ans = 1
for num, cnt in div:
    if cnt >= N:
        ans = max(ans, num)

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
divisors = sorted(sum((list({n, M // n}) for n in range(1, int(M ** 0.5) + 1) if not M % n), []), reverse=True)

for d in divisors:
    if M // d >= N:
        print(d)
        break

Submission status: Accepted

Solution code:
def main():
    n,m=map(int,input().split())
    ans=0
    for i in range(1,min(int(m**0.5//1)+2,m//n+1)):
        if m%i==0:
            if i>=n:
              ans=max(m//i,ans)
            else:
              ans=max(i,ans)
    print(ans)     
if __name__=='__main__':
    main()

Submission status: Accepted

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

def calc_divisors(n):
    res = []
    i = 1
    while i * i <= n:
        if n % i == 0:
            res.append(i)
            res.append(n // i)
        i += 1
    res = list(set(res))
    return res

divisors = calc_divisors(m)
divisors.sort(reverse=True)

for divisor in divisors:
    if m >= n * divisor:
        print(divisor)
        break

Submission status: Accepted

Solution code:
# coding: utf-8
import math
N,M=map(int,input().split())
A=[]
for i in range(1,int(math.sqrt(M))+1):
    if M%i==0:
        if M//i>=N:
            A.append(i)
            if i>=N and M//i>i:
                A.append(M//i)

A.sort()

ans=A[-1]

print(ans)

Submission status: Accepted

Solution code:
x,y=map(int,input().split())
a=1
k=pow(y,0.5)
for i in range(1,int(k)+1):
    if y%i==0:
        if i*x<=y:
            a=max(a,i)
        if (y//i)*x<=y:
            a=max(a,y//i)
print(a)

Submission status: Accepted

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

def get_div(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 = get_div(m)
divs.reverse()
mx = m//n

for d in divs:
    if d<=mx:
        print(d)
        exit()