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())
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
h=make_divisors(m)
h.sort()
for u in h:
    if u>=n:
        print(m//u)
        break

Submission status: Accepted

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

for i in range(1, int(math.sqrt(M))+1):
    if M % i == 0.0:
        if M // i >= N and ans < i:
            ans = i
        if M // (M // i) >= N and ans < (M // i):
            ans = M // i
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ret = 1
d = 1
while d * d <= m:
    if m % d == 0:
        if d >= n:
            ret = max(ret, m // d)
        if m // d >= n:
            ret = max(ret, d)
    d += 1
print(ret)

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split(' ')))
p = []
for ct in range(2, 10000000):
    if M % ct == 0:
        p.append(ct)
        p.append(M//ct)
p.append(M)
# 14 => [1, 2, 7, 14]
# 3, 14 => 2 + 4 + 8 = 14, 2 * (1 + 2 + 4)
# 2. 14 => 7 + 7 ~> 7 * (1 * 1)
# 1, 14 => 14 => 14 * (1)
 
# 12 => [1, 2, 3, 4, 6, 12]
# 3, 12 => 4 + 4 + 4 = 12, 4 * (1 + 1 + 1)
 
# 125 => [1, 5, 25, 125]
# 1, 125 = 125 = 125 * (1)                                          => 125
# 2, 125 = 100 + 25 = 25 * (4 + 1)                                  => 25  (!)
# 3, 125 = 75 + 25 + 25 = 25 * (3 + 1 + 1)                          => 25
# 4, 125 = 50 + 25 + 25 + 25 = 25 * (2 + 1 + 1 + 1)                 => 25
# 5, 125 = 25 + 25 + 25 + 25 + 25 = 25 * (1 + 1 + 1 + 1 + 1)        => 25
# 6, 125 = 25 + 25 + 25 + 25 + 20 + 5 = 5 * (5 + 5 + 5 + 5 + 4 + 1) => 5   (!)
ans = 1
for t in sorted(p):
    if M / N >= t:
        ans = t
print(ans)

Submission status: Accepted

Solution code:
import bisect

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 solv():
    N, M = map(int, input().split())
    divisors = make_divisors(M)
    l_i, r_i = bisect.bisect_left(divisors, N), bisect.bisect_right(divisors, N)
    print(M//divisors[min(l_i, r_i)])

if __name__ == '__main__':
    solv()

Submission status: Accepted

Solution code:
#再提出
import bisect
n,m = map(int, input().split( ))

t = m//n

fct_sup = int(m**(1/2)) + 1

fct = []
fct2 = []
for f in range(1,fct_sup+1):
    if m%f == 0:
        fct.append(f)
        fct2.append(m//f)
if fct[-1] == fct2[-1]:
    fct.pop()
fct2.reverse()
fct += fct2
i = bisect.bisect_right(fct,t)
print(fct[i-1])

Submission status: Accepted

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

t = m//n

fct_sup = int(m**(1/2)) + 1

fct = []
fct2 = []
for f in range(1,fct_sup+1):
    if m%f == 0:
        fct.append(f)
        fct2.append(m//f)
if fct[-1] == fct2[-1]:
    fct.pop()
fct2.reverse()
fct += fct2
i = bisect.bisect_right(fct,t)
print(fct[i-1])

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    if n == 1:
        print("Hello World")
    else:
        print(II()+II())
    return

#B
def B():
    n, t = LI()
    ans = inf
    for _ in range(n):
        c, ti = LI()
        if ti <= t:
            ans = min(ans, c)
    if ans == inf:
        print("TLE")
        return
    print(ans)
    return

#C
def C():
    n = II()
    xyh = LIR(n)
    xyh.sort(key = lambda x:x[2], reverse = True)
    x1, y1, h1 = xyh[0]
    del xyh[0]
    for x in range(101):
        for y in range(101):
            h = abs(x - x1) + abs(y - y1) + h1
            flg = True
            for xn, yn, hn in xyh:
                if max(h - abs(x - xn) - abs(y - yn), 0) == hn:
                    continue
                flg = False
                break
            if flg:
                print(x, y, h)
                return 
    return

#D
def D():
    n, m = LI()
    ans = 1
    for i in range(1,int(math.sqrt(m)+1)):
        if m % i == 0:
            a = m // i
            #print(i,a)
            if a * n <= m:
                ans = max(ans, a)
            if i * n <= m:
                ans = max(ans, i)
    print(ans)
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Accepted

Solution code:
import sys, re
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
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

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
x = M // N
l = make_divisors(M)
# print(l)
for i in l:
    if i <= x:
        print(i)
        break

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
K = m//n
ans = 0
i = 1
while i <= K:
  if m % i == 0:
    if m//i <= K:
      ans = m//i
      break
    ans = i
    K = min(m//n, m//i)
  i += 1
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right
N, M = map(int, input().split())


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

    divisors.sort()
    return divisors


divisors = make_divisors(M)
print(divisors[bisect_right(divisors, M // N) - 1])

Submission status: Accepted

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

li = []
for i in range(1, M + 1):
    if i * i > M:
        break
    if M % i == 0:
        li.append(i)
        li.append(M // i)

ans = 1

li.sort(reverse=True)

for i in li:
    if N * i <= M:
        ans = i
        break

print(ans)

Submission status: Accepted

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

d=list()
for i in range(1,int(m**0.5)+1):
  if m%i==0:
    d.append(i)
    if i!=m//i:
      d.append(m//i)

c=1
for i in range(len(d)):
  if m//d[i]>=n:
    c=max(d[i],c)

print(c)

Submission status: Accepted

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

d=list()
for i in range(1,int(m**0.5)+1):
  if m%i==0:
    d.append(i)
    if i!=m//i:
      d.append(m//i)

d.sort()

c=1
for i in range(len(d)):
  if m//d[i]>=n:
    c=max(d[i],c)

print(c)

Submission status: Accepted

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

fct = []
fct2 = []
sq = int(m**(1/2))
if sq + 1 ==m:
    sq += 1

for f in range(1, sq + 1):
    if m%f == 0:
        fct.append(f)
        fct2.append(m//f)
if fct2[-1] == fct[-1]:
    fct2.pop()

fct2.reverse()

fct += fct2

k = m//n
ind = bisect.bisect_left(fct,k)

print(fct[ind-1] if k<fct[ind] else fct[ind])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
p = m // n
while m % p != 0:p -= 1
print(p)

Submission status: Accepted

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

    start = m//n

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

main()

Submission status: Accepted

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

li=[]
for d in range(1,m+1):
    if d*d>m:
        break
    if m%d==0:
        li.append(d)
        li.append(m//d)
        
li.sort()

ans=0

for d in li:
    if d*n<=m:
        ans=d
print(ans)

Submission status: Accepted

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

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

for i in d:
  if i*N<=M:
    print(i)
    exit()

Submission status: Accepted

Solution code:
import math

n,m = map(int,input().split())
m_div = []
for i in range(1,math.ceil(math.sqrt(m)+1)):
  if m%i ==0:
    m_div.extend([i,m//i])
m_div = list(set(m_div))
m_div.sort(reverse = True)
for div in m_div:
  if div >= n:
    ans = m//div
  else:
    break
print(ans)

Submission status: Accepted

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

"""
解説動画
https://youtu.be/CURWJ1Dr44A?t=1708
"""

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

    divs = set()  # Mの約数を格納する

    # Mの約数をすべて調べる
    n = 1
    while n*n <= M:
        if M%n == 0:
            # nがMの約数ならば
            divs.add(n)
            divs.add(M//n)
        n += 1

    # Mの約数dの中で、d*N <= Mを満たす最大のものが答え
    ans = 0
    for d in divs:
        if d*N <= M:
            ans = max(ans, d)

    print(ans)


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

    divs = set()

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

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


if __name__ == "__main__":
    solve2()

Submission status: Accepted

Solution code:
from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]
ans = 1
d = 1
while d ** 2 <= M:
    if M % d == 0:
        if M // d >= N:
            ans = max(d, ans)
        if M // (M // d) >= N:
            ans = max(M // d, ans)
    d += 1

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left
import random
from itertools import permutations, accumulate, combinations
import sys
import string


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 10 ** 9 + 7


n, m = LI()


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



min_d = min([d for d in make_divisors(m) if d >= n])
print(m // min_d)

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

ans = -float('inf')
N,M = map(int,input().split())
for div in make_divisors(M):
  if M//div >= N: ans = max(ans, div)
print(ans)

Submission status: Accepted

Solution code:
N, M=map(int, input().split())
def f(x):
  out=[]
  a=int(pow(x, 1/2))
  for i in range(1, a+1):
    if x%i==0:
      out.append(i)
      j=x//i
      if i!=j:
        out.append(j)
        
  out.sort()
  return out

temp=f(M)

i=0
while temp[i]<N:
  i+=1
  
print(temp[-i-1])

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


prime_list = make_divisors(m)
max_ = 0
for i in prime_list:
    if i <= m/n and i > max_:
        max_ = i
print(max_)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())  # N個の数列, 合計がM, 求めたいのは最大公約数の最大値

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

divs.sort()

ans = 0
for d in divs:
    if M//N >= d:
        ans = d
    else:
        break

print(ans)

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n,m=map(int,input().split())

tmp=m//n
for i in range(tmp):
    if m%(tmp-i)==0:
        print(tmp-i)
        break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def make_divisors(div, n):
    divisors = []
    mx = 0
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if n // i >= div:
                mx = max(mx, i)
            if i != n // i:
                divisors.append(n//i)
                if i >= div:
                    mx = max(mx, n // i)
    return divisors, mx

n,m = map(int, input().split())
divisors, mx = make_divisors(n, m)
print(mx)

Submission status: Accepted

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

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

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

    divisors = make_divisors(M)

    for d in divisors:
        tmp = M - d * N
        if tmp >= 0 and tmp % d == 0:
            print(d)
            break
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
maxi=0
import math
num=math.sqrt(m)
nums=math.floor(num)

for i in range(1,nums+1):
    if m%i==0:
        number1=i
        number2=m//i
        #二つの約数について比べる
        #number1<number2
        #m//number1>m//number2
        if m//number1>=n and m//number2>=n:
            maxi=max(number2,maxi)
        elif m//number1>=n and m//number2<n:
            maxi=max(maxi,number1)
        
    else:
        continue
print(maxi)

Submission status: Accepted

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

Submission status: Accepted

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

# 約数を列挙 (ex. 6 => [1,2,3,6])
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())
    divs = make_divisors(M)
    for d in divs:
        k = M//d
        if k >= N:
            print(d)
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

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

ans = 1
for i in range(1, math.ceil(M ** 0.5)):
    if M % i == 0:
        if i*N <= M:
            ans = max(ans, i)
        if (M//i)*N <= M:
           ans = max(ans, M//i) 


print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import heapq

N,M=map(int,input().split())
ans=0
l=[1,M]

for i in range(2,-int(-M**0.5//1)):
    if M%i==0:
        l.append(i)
        l.append(int(M/i))

for item in l:
    if (M-N*item)>=0:
        ans=max(ans,item)
    else:
        pass
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())
K=make_divisors(M)

L=[]
for k in K:
  if k*N<=M:
    L.append(k)
print(max(L))

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())
arr = [i for i in make_divisors(M) if i>=N]
print(M//min(arr))

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())
arr = [i for i in make_divisors(M) if i>=N]
print(M//min(arr))

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(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)
    divisors.sort()
    return divisors

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

Submission status: Accepted

Solution code:
import math

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

q = int(math.sqrt(m))+1
li = [0 for i in range(10**6)]

for i in range(1,q):
    if (m%i) == 0:
        li[i] = 1
        
ans = 1
for i in range(1,q):
    if (li[i]==1) and (i*n<=m):
        ans = max(i,ans)
        
    if (li[i]==1) and (m*n<=m*i):
        ans = max((m/i),ans)
    

print(int(ans))

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 += [i]
    if i != m//i:
      Div += [m//i]
Div.sort(reverse=True)
for div in Div:
  if div <= m//n:
    print(div)
    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())

    div = make_divisors(M)
    sort_div = sorted(div)

    ans = 0
    for a in sort_div:
        if a <= M // N:
            ans = a
        else:
            break

    print(ans)


main()

Submission status: Accepted

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

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

ans = 0
d = divisor(m)

for x, y in d:
    if x >= n:
        ans = max(ans, y)
    if y >= n:
        ans = max(ans, x)
print(ans)

Submission status: Accepted

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


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

    ans = 1
    i = 1
    while i**2<=M:
        if M%i==0:
            if i<=M//N:
                ans = max(ans, i)
            if M//i<=M//N:
                ans = max(ans, M//i)
        i += 1
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

n, m = map(int, input().split())
mm = m // n
res = []
for k in range(1, int(math.sqrt(m)) + 1):
    if m % k == 0:
        if k > mm:
            break
        if m // k <= mm:
            k = m // k
        res.append(k)
print(max(res))

Submission status: Accepted

Solution code:
import math

n, m = map(int, input().split())
mm = m // n
res = []
for k in range(int(math.sqrt(m)), 0, -1):
    if m % k == 0:
        if k > mm:
            continue
        if m // k <= mm:
            k = m // k
        res.append(k)
print(max(res))

Submission status: Accepted

Solution code:
import collections
import itertools
import math


def eratosthenes(n):
    sieve = [True for _ in range(n + 1)]
    sieve[0] = False
    sieve[1] = False

    def _update(p):
        if sieve[p]:
            for i in range(p * 2, n + 1, p):
                sieve[i] = False

    _update(2)
    p = 3
    while p * p <= n:
        _update(p)
        p += 2
    return sieve


n, m = map(int, input().split())
m2 = math.ceil(math.sqrt(m)) + 1
sieve = eratosthenes(m2)
counter = collections.Counter()

mm = m
for k in range(2, m2):
    if sieve[k] and m % k == 0:
        while mm % k == 0:
            mm //= k
            counter[k] += 1
if mm > 1:
    counter[mm] += 1

es = [range(k + 1) for k in counter.values()]
res = 1
for ks in itertools.product(*es):
    x = 1
    for p, k in zip(counter.keys(), ks):
        x *= p**k
    if x <= m // n:
        res = max(res, x)
print(res)

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())
tmp = []
for i in make_divisors(m):
    if m % i == 0 and m // i >= n:
        tmp.append(i)
print(tmp[-1])

Submission status: Accepted

Solution code:
import sys
import math

N, M = map(int, input().split())
factors = [1]

if M % N == 0:
    print(M // N)
    sys.exit()

for m in range(2, int(math.sqrt(M)) + 1):
    tmp = M
    while tmp % m == 0:
        factors.append(m)
        factors.append(tmp // m)
        tmp = tmp // m
factors.append(M)

factors.sort()

for i in range(len(factors)):
    if factors[i] * N > M:
        ans = factors[i - 1]
        break
print(factors[i - 1])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())  # 項数N, Aの和M

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

# Mの約数を列挙する
divs = []
ans = 1


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

# print(divs)
# 約数が全て手に入った
for d in divs:
    if M >= N * d:
        ans = max(ans, d)

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())  # 項数N, Aの和M

ans = 1
for i in range(1, int(M**(1/2))+1):
    if M % i != 0:
        continue
    j = M // i  # jはどんどん小さくなる
    if j >= N:
        ans = max(ans, i)
    if i >= N:
        ans = max(ans, j)

print(ans)

Submission status: Accepted

Solution code:
#16:44
n,m = map(int,input().split())
div = []
rdiv = []
for i in range(1,int(m**.5)):
  if m % i == 0:
    div.append(i)
    rdiv.append(m//i)
if m % int(m**.5) == 0:
  div.append(int(m**.5))
rdiv.reverse()
div += rdiv
for x in div:
  if x >= n:
    print(m//x)
    break

Submission status: Accepted

Solution code:
def divisor(n,N): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i*N)
            table.append(n//i*N)
        i += 1
    table = list(set(table))
    return table
from bisect import bisect_right
#b = bisect_left(A,C)

N,M = [int(x) for x in input().split()]
table = divisor(M,N)
table.sort()
b = bisect_right(table,M)
print(table[b-1]//N)

Submission status: Accepted

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

n, m = [ int(v) for v in input().split() ]
divisors_list = divisors(m)

ans = 1
for i in divisors_list:
    if i[1] >= n:
        ans = i[0]
print(ans)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    md = 1
    for i in range(1, int(m ** 0.5) + 1):
        if m % i == 0:
            if n <= m // i:
                md = max(md, i)
            if n <= i:
                md = max(md, m // i)
    print(md)


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

Submission status: Accepted

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

# Mを i*j jがN以上なら i は a の 公約数である
# 最大値を記録しながら、公約数を全て探索
max_num = 1
for i in range(1, int(M**(1/2))+2):
    if M%i:
        continue
    j = M // i
    if j >= N:
        max_num = max(max_num, i)
    if i >= N:
        max_num = max(max_num, j)

print(max_num)

Submission status: Accepted

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

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

yakusu = []

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

Submission status: Accepted

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

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

m = math.floor(math.sqrt(M))
b = M == m * m
O = set([m]) if b else set()
for i in range(m - b,0,-1):
    if M % i == 0:
        O |= {i,M//i}

O = sorted(O)

# とりあえず計算量とか考えず実装してみる
# Oは照準にソートされている
# Oの要素から o <= M / N となる最大のo

a = M / N
left = 0
right = len(O)-1
while left + 1 != right:
    middle = (left + right)//2
    if O[middle] <= a:
        left = middle
    else:
        right = middle
    
print(O[left])

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
ans = 1
lst = make_divisors(m)
lst.sort()
for d in lst:
    if m>=d*n:
        ans = d
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


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

divisors = make_divisors(m)

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

Submission status: Accepted

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

Submission status: Accepted

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

limit = int(m**(0.5))
ans = 1
for d in range(1, limit+1):
    if m % d == 0:
        if m>=d*n:
            ans = max(ans,d)
        if m>=(m//d)*n:
            ans=max(ans,(m//d))

print(ans)

Submission status: Accepted

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

limit=int(m**(1/2))+1

divisors=[]
for d in range(1,limit):
    if m%d==0:
        divisors.append(d)
        divisors.append(m//d)

divisors.sort()
ans=1

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

Submission status: Accepted

Solution code:
def divisors(N):
    U = int(N ** 0.5)
    L = {i for i in range(1, U + 1) if N % i == 0}
    R = {N // r for r in L}
    return L | R

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))

Submission status: Accepted

Solution code:
def divisors(N):
    U = int(N ** 0.5)
    L = [i for i in range(1, U) if N % i == 0]
    C = [U] if N % U == 0 else []
    R = [N // r for r in reversed(L)]
    return L + C + R

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))

Submission status: Accepted

Solution code:
def divisors(N):
    U = int(N ** 0.5)
    L = [i for i in range(1, U) if N % i == 0]
    C = [U] if M % U == 0 else []
    R = [N // r for r in reversed(L)]
    return L + C + R

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))

Submission status: Accepted

Solution code:
def divisors(N):
    U = int(N ** 0.5)
    res = [i for i in range(1, U) if N % i == 0]
    if N % U == 0:
        res.append(U)
    res += [N // r for r in reversed(res)]
    return res

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))

Submission status: Accepted

Solution code:
def divisors(N):
    U = int(N ** 0.5)
    L, R = [], []
    all((L.append(i), R.append(N // i)) for i in range(1, U) if N % i == 0)
    if N % U == 0:
        L.append(U)
    R.reverse()
    L += R
    return L

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))

Submission status: Accepted

Solution code:
def divisors(N):
    U = int(N ** 0.5)
    res = []
    any(res.extend((i, N // i)) for i in range(1, U) if N % i == 0)
    if N % U == 0:
        res.append(U)
    res.sort()
    return res

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))

Submission status: Accepted

Solution code:
def divisors(N):
    U = int(N ** 0.5)
    res = []
    *_, = (res.extend((i, N // i)) for i in range(1, U) if N % i == 0)
    if N % U == 0:
        res.append(U)
    res.sort()
    return res

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))

Submission status: Accepted

Solution code:
def divisors(N):
    U = int(N ** 0.5)
    res = []
    *_, = (res.extend([i, N // i]) for i in range(1, U) if N % i == 0)
    if N % U == 0:
        res.append(U)
    res.sort()
    return res

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))