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:
def divisors(N):
    U = int(N ** 0.5)
    res = []
    for i in range(1, U):
        if N % i == 0:
            res += [i, N // i]
    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):
    i = 1
    U = int(N ** 0.5)
    res = []
    for i in range(1, U):
        if N % i == 0:
            res += [i, N // i]
    if N % i == 0:
        res.append(i)
    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):
    res = []
    i = 1
    for i in range(1, int(N ** 0.5)):
        if N % i == 0:
            res += [i, N // i]
    if N % i == 0:
        res.append(i)
    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):
    res = []
    i = 1
    while i * i < N:
        if N % i == 0:
            res += [i, N // i]
        i += 1
    if N % i == 0:
        res.append(i)
    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):
    res = []
    i = 1
    while i * i < N:
        if N % i == 0:
            res += [i, N // i]
        i += 1
    if i * i == N and N % i == 0:
        res.append(i)
    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):
    res = []
    i = 1
    while i * i < N:
        if N % i == 0:
            res.extend([i, N // i])
        i += 1
    if i * i == N and N % i == 0:
        res.append(i)
    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):
    res = []
    i = 1
    while i * i < N:
        if N % i == 0:
            res.append(i)
            res.append(N // i)
        i += 1
    if i * i == N and N % i == 0:
        res.append(i)
    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):
    res = []
    i = 1
    while i * i <= N:
        if N % i == 0:
            res.append(i)
            if i * i != N:
                res.append(N // i)
        i += 1
    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):
    res = []
    i = 1
    while i * i <= N:
        if N % i == 0:
            res.append(i)
            if i != N // i:
                res.append(N // i)
        i += 1
    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):
    res = []
    i = 1
    while i * i <= N:
        if N % i == 0:
            res.append(i)
            q = N // i
            if i != q:
                res.append(q)
        i += 1
    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):
    res = []
    i = 1
    while i * i <= N:
        q, r = N // i, N % i
        if r == 0:
            res.append(i)
            if i != q:
                res.append(q)
        i += 1
    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):
    res = []
    i = 1
    while i * i <= N:
        q, r = divmod(N, i)
        if r == 0:
            res.append(i)
            if i != q:
                res.append(q)
        i += 1
    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:
N, M = map(int, input().split())
print(next(d for d in reversed(range(M // N + 1)) if M % d == 0))

Submission status: Accepted

Solution code:
import math
N, M = map(int, input().split())
x = M//N
mid = int(math.sqrt(M))
if x >= mid:
    ans = []
    for i in range(1, mid+1):
        if M%i == 0:
            ans.append(i)
            if M//i <= x:
                ans.append(M//i)
    print(max(ans))
else:
    for i in range(x, 0, -1):
        if M%i == 0:
            print(i)
            break

Submission status: Accepted

Solution code:
import math
N, M = map(int, input().split())
ulim = M//N
mid = int(math.sqrt(M))
if ulim >= mid:
    ans = []
    for i in range(1, mid+1):
        if M%i == 0:
            ans.append(i)
            if M//i <= ulim:
                ans.append(M//i)
    print(max(ans))
 
else:
    for i in reversed(range(1, ulim+1)):
        if M%i == 0:
            print(i)
            break

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
x = M//N
max = 1
for i in range(x, 0, -1):
    mod = M - (N-1)*i
    if mod%i == 0:
        max = i
        break
print(max)

Submission status: Accepted

Solution code:
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

ans = 0
for d in make_divisors(M):
    if N*d <= M and d > ans:
        ans = d
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
Ds = []
for i in range(1, M+1):
  if i*i > M:
    break
  if M%i == 0:
    j = M//i
    Ds.append(i)
    Ds.append(j)
#print(Ds)
r = max(filter(lambda i: M//i >= N, Ds))
print(r)

Submission status: Accepted

Solution code:
def find_prime_factor(num):
    if num & 1 == 0:
        return 2
    for i in range(3, int(num ** (1 / 2)) + 1):
        if num % i == 0:
            return i
    return num


def prime_factorization(num):
    subtract = num
    result = []
    while subtract > 1:
        factor = find_prime_factor(subtract)
        result.append(factor)
        subtract //= factor
    return result


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

prime_factors = prime_factorization(m)
# prime and prime's power.
power = {}
for prime in prime_factors:
    if prime in power:
        power[prime] += 1
    else:
        power[prime] = 1

# enum all divisors.
divisors = [1]
for prime in power:
    divisors += [divisor * prime ** pw
                 for pw in range(1, power[prime] + 1)
                 for divisor in divisors]
divisors.sort()

answer = 0
for divisor in divisors:
    if divisor <= int(m / n):
        answer = divisor
    else:
        break

print(answer)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
M2 = M // N + 1 #最低2

ans = 1

for i in reversed(range(1, M2)):
  #print(i)
  if M % i == 0:# iがMの約数のとき、最大公約数となる可能性がある。
    Sho = M // i
    if Sho >= N:
      ans = i
      print(i)
      quit()
      
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)
#print(DIV)

for i in DIV:
    if M - i*N >= 0:
        ans = i
print(ans)

Submission status: Accepted

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

d = sorted(d,reverse = True)
#print(d)

for j in range(len(d)):
    if m // d[j] >= n:
        print(d[j])
        break

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

an = m //n
while an*n != m:
  an = m//n
  n = 1 + (m-1)//an
  
print(an)

Submission status: Accepted

Solution code:
# ABC112D - Partition
from bisect import bisect_left as bs


def divisors(n: int) -> list:
    """
    Compute divisors of a number.
    
    Args: n (int): an integer to be evaluated.
    Returns: div (set): set of divisors
    """
    div = set()
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            div.add(i)
            div.add(n // i)
    return sorted(div)


def main():
    N, M = tuple(map(int, input().split()))
    if M % N == 0:
        print(M // N)
    else:
        div = divisors(M)
        ans = div[bs(div, M / N) - 1]
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
p = m // n
ans_1 = 0
if p > 100000:
    for i in range(1, 10001):
        if m % i == 0 and i >= n:
            ans_1 = m // i
            break
for i in range(min(p, 100000), 0, -1):
    if m % i == 0:
        ans_2 = i
        break
    else:
        continue
print(max(ans_1, ans_2))

Submission status: Accepted

Solution code:
import sys

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

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

divisors = make_divisors(m)

for i in range(1, len(divisors)+1):
    if divisors[i*-1] * n <= m:
        print(divisors[i*-1])
        sys.exit()

Submission status: Accepted

Solution code:
import math

def main():
    N, M = map(int, input().split())
    divs = sorted(divisors(M), reverse = True)
    for d in divs:
        if M // d >= N:
            return d
    return -1


def divisors(i):
    ans = set()
    for j in range(1, int(math.sqrt(i))+1):
        if i % j == 0:
            ans.add(j)
            ans.add(i // j)
    return list(ans)

if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

ans = 1
for i in range(1, int(m**0.5)+2):
  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:
N, M = map(int, input().split())
g = []
for i in range(1,M+1):
  if M%i==0:
    j = M//i
    if i<=M//N:
      g += [i]
    if j<=M//N:
      g += [j]
  if i>M**0.5:
    break
print(max(g))

Submission status: Accepted

Solution code:
from math import factorial

def divisors(n):
    e = int(n**0.5+1)
    k = int(0)
    div=[0]*e
    divs =[]
    for i in range(1,e):
        if n%i == 0:
            div[k] = i
            k +=1

    i = int(0)
    while div[i]!=0 : i +=1
    end=int(i)

    del div[end:]
    divs = div
    for i in reversed(div):
        a = int(n//i)
        if not a in divs:
            div.append(a)

    return(div)

N, M = map(int, input().split())
L = divisors(M)
maxans = int(M//N)

anst = int(0)
for i in L:
    if i > maxans:
        break
    else:anst = i

ans = anst
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ls = []
for i in range(1,M+1):
  if M%i==0:
    j = M//i
    if i<=M//N:
      ls += [i]
    if j<=M//N:
      ls += [j]
  if M**0.5<i:
    break
print(max(ls))

Submission status: Accepted

Solution code:

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

lis = []

now = 1
while now ** 2 <= M:

    if M % now == 0 and now ** 2 != M:
        lis.append(now)
        lis.append(M // now)

    elif now ** 2 == M:
        lis.append(now)
        
    now += 1

maxi = 1
lis.sort()

for i in lis:

    if  M // i >= N:

        maxi = i

print (maxi)

Submission status: Accepted

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

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


def enum_div(num):
    ret = list()
    for i in range(1, int(num ** 0.5) + 1):
        if num % i == 0:
            ret.append(i)
            if i != num // i:
                ret.append(num // i)
    return ret


div = sorted(enum_div(m), reverse=True)

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

Submission status: Accepted

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

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

    # divisors.sort()
    return divisors

ans=(make_divisors(m))
ans.sort()

for i in range(len(ans)):
    if ans[i]>m//n:
        print(ans[i-1])
        break
else:
    print(ans[-1])

Submission status: Accepted

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

def solve():
  n,m = (int(i) for i in input().split())
  div = makedivisor(m)
  if len(div) == 0:
    print(1)
    exit()
  else:
    ans = 1
    for i in div:
      if (m-(n*i)) >= 0:
        ans = max(ans,i)
    print(ans)
solve()

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

print(ans)

Submission status: Accepted

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

def divisor(x) :
    d = []
    i = 1
    while i**2 <= x :
        if x%i == 0 :
            d.append(i)
            d.append(x//i)
        i += 1
    return d

maximum = 0
for d in divisor(m) :
    if d >= n :
        maximum = max(maximum, m//d)
print(maximum)

Submission status: Accepted

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

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

Submission status: Accepted

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

  for i in range(M // N, 0, -1):
    if M % i == 0:
      print(i)
      break
      
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())

l = make_divisors(M)
l.sort()
for i in range(len(l)):
    if l[i] >= N:
        a = l[i]
        break

ans = M // a
print(ans)

Submission status: Accepted

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

d = int(M**(1/2))
div_list = []
while d >= 1:
    if M%d == 0:
        div_list.append(d)
        div_list.append(M//d)
    d -= 1

div_list.sort(reverse = True)
for i in range(len(div_list)):
    if div_list[i] <= M//N:
        print(div_list[i])
        break

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


divs = make_divisors(M)

i = bisect.bisect_right(divs, int(M/N))
print(divs[i-1])

Submission status: Accepted

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

# d = defaultdict(int)

# for i in range(2, M+1):
#     while M % i == 0:
#         d[i] += 1
#         M //= i
#     if M == 1:
#         break


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

    divisors.sort()
    return divisors


divs = make_divisors(M)


i = bisect.bisect_right(divs, int(M/N))

print(divs[i-1])

Submission status: Accepted

Solution code:
import heapq
n,m = (int(x) for x in input().split())
a1 = []
a2 = []
for i in range(1, int(m**0.5)+1):
  if(m%i == 0):
    a1.append(i)
    a2.append(m//i)
    
a1.extend(a2[::-1])
i = 0

while(i <= len(a1)):
  if(a1[i] >= n):
    print(m//a1[i])
    break
  i += 1

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
l = []
for i in range(1, int(m**(1/2)) + 1):
	if m % i == 0:
		l.append(i)
		l.append(m // i)
l.sort()
l=l[::-1]
for i in l:
    if m//n>=i:
        print(i)
        break

Submission status: Accepted

Solution code:
import math

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

MAX = M // N

def prime2(n):
    factor = {}
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            if not num in factor.keys():
                factor[num] = 1
            else:
                factor[num] += 1
    if n != 1:
        if not n in factor.keys():
            factor[n] = 1
        else:
            factor[n] += 1
    return factor


def prob(i, s, ans):
    if i == len(A):
        if s <= MAX:
            ans = max(ans, s)
        return ans
    n, m = A[i]
    for j in range(m+1):
        ans = prob(i+1, s*n**j, ans)
    return ans

A = list(prime2(M).items())
ans = prob(0, 1, 1)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

# Mの約数dのうち、 dN <= M を満たす最大のdが解
ans = max(
    (
        M // d if (M // d) * N <= M else
        d if d * N <= M else
        1
    )
    for d in range(1, int(M**0.5) + 10)
    if M % d == 0
)

print(ans)

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
  return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
  read_all = [tuple(map(int, input().split())) for _ in range(N)]
  return map(list,zip(*read_all))

#################

N,M = II()

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

ans = 1
kouho = make_divisors(M)
for i in kouho:
  if M%i==0 and i*N<=M:
    ans = i
print(ans)

Submission status: Accepted

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

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

    divisors.sort()
    return divisors

import bisect
d = make_divisors(m)
idx = bisect.bisect_left(d, n)
print(m // d[idx])

Submission status: Accepted

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

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()
    return divisors
M_div = make_divisors(M)

for i in range(len(M_div)):
	if N <= M_div[i]:
		break

a = len(M_div)-i
print(M_div[a-1])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from math import sqrt
from bisect import bisect_right

def main():
	n, m = map(int, input().strip().split())
	M = int(sqrt(m))
	ans = 1
	for i in range(1, M+1):
		if m % i == 0:
			if i*n <= m:
				ans = max(ans, i)
			if m//i * n <= m:
				ans = max(ans, m//i)
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from math import sqrt
from bisect import bisect_right

def main():
	n, m = map(int, input().strip().split())
	M = int(sqrt(m))
	l = []
	for i in range(1, M+1):
		if m % i == 0:
			l.append(i)
			l.append(m // i)
	l.sort()
	k = m//n
	ind = bisect_right(l, k)
	# print(l)
	print(l[ind-1])

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import math
def judge(max_d,x):
    if x<=max_d:
        return x
    else:
        return 1

def main():
    n,m = map(int,input().split())
    max_d = m//n
    sq = math.floor((math.sqrt(m)))
    ans = 1
    for i in range(1,sq):
        if m%i==0:
            x1 = judge(max_d,i)
            x2 = judge(max_d,m//i)
            x = max(x1,x2)
            ans = max(ans,x)
        else:
            pass
    print(ans) 
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)
        l.append(m//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())

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)
div.sort(reverse = True)

for d in div:
    if d*N > M:continue
    break
print(d)

Submission status: Accepted

Solution code:
import math

n, m = list(map(int, input().split()))
reg = (m / n)
k = 1
for i in range(1, int(math.sqrt(m) + 1)):
    if m % i == 0:
        a = m/i
        b = i
        if reg >= b and k < b:
            k = b
        if reg >= a and k < a:
            k = a
print(int(k))

Submission status: Accepted

Solution code:
# 2019/08/01

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

def divisors(n,m):
    div=[]
    end=int(pow(m,0.5))
    for i in range(1,end+1):
        if m%i==0:
            div.append(i)
            div.append(m//i)
    div.sort(reverse=True)
    return div

res=divisors(n,m)
for e in res:
    if m//n>=e:
        print(e)
        break

Submission status: Accepted

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

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

print(max(v for v in divisor if v <= M // N))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
divisor = []
for i in range(int(m ** 0.5)):
    if m % (i + 1) == 0:
        divisor.append(i + 1)
        divisor.append(m // (i + 1))
divisor.sort(reverse = True)
for i in divisor:
    if m // i >= n:
        print(i)
        break

Submission status: Accepted

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

f1, f2 = [], []

k = 1
while k*k<=M:
    if M%k==0:
        f1.append(k)
        f2.append(M//k)
    k+=1

for f in f1 + list(reversed(f2)):
    if f>=N:
        print(M//f)
        break

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC112 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

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

for i in range(1,m//n+1)[::-1]:
    if m % i == 0:
        print(i)
        break

Submission status: Accepted

Solution code:
import math


def main():
    N, M = map(int, input().split())
    rt = int(math.sqrt(M))
    div = []
    for i in range(1, rt+1):
        if M % i == 0:
            div.append(i)
            if i ** 2 != M:
                div.append(M//i)
    ans = 1
    for d in div:
        if d * N <= M:
            ans = max(ans, d)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

def get_divs(a):
	divs = [1, a]
	for n in range(2, int(a ** 0.5)):
		if a % n == 0:
			divs.append(n)
			divs.append(a // n)
	return divs

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

	divs = get_divs(M)
	divs.sort()
	divs.reverse()
	divs = filter(lambda x:x <= M // N, divs)

	for div in divs:
		if (M - N * div) % div == 0:
			print(div)
			break

main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

divisor = []
c = 1
while c <= M**0.5:
    if M % c == 0:
        divisor.append(c)
    c += 1
divisor2 = []
for i in range(len(divisor)):
    divisor2.append(M//divisor[i])
    
divisor = divisor + divisor2
divisor.sort(reverse=True)

for j in range(len(divisor)):
    if M//divisor[j] >= N:
        ans = divisor[j]
        break
        
print(ans)

Submission status: Accepted

Solution code:
def get_divisor(n):
    a,b = [],[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            a.append(i)
            b.append(n//i)
    if a[-1]==b[-1]:b.pop()
    a.extend(b[::-1])
    return a

N,M = map(int,input().split())
print(max(n for n in get_divisor(M) if n<=M//N))

Submission status: Accepted

Solution code:
import math 
N,M=map(int,input().split())
a=M//N
ans=0
for i in range(1,int(math.sqrt(M))+1):
    if M%i==0:
        if i<=a and i>ans:ans=i
        if M//i<=a and M//i>ans:ans=M//i
print(ans)

Submission status: Accepted

Solution code:
import math, bisect

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

s = set()
for x in range(1, math.ceil(math.sqrt(m)) + 1):
    if m % x == 0:
        s.add(x)
        s.add(m // x)

t = list(sorted(s))
i = bisect.bisect_left(t, n)
print(m // t[i])

Submission status: Accepted

Solution code:
from math import *
N,M=map(int,input().split())
d1,d2=[],[]
for n in range(1,int(sqrt(M))+1):
    if M%n == 0:
        d1.append(n)
        d2.append(M//n)
divs=d2+d1[::-1]
for d in divs:
    if d*N <= M:
        print(d)
        break

Submission status: Accepted

Solution code:
# ND <= M
# D <= M // N
# DはMの約数


def divisors(n):
    """
    nの約数をO(√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 = 0
for D in divisors(M):
    if ans < D <= M // N:
        ans = D
print(ans)

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    divisors = get_divisors(m)
    small = [d for d in divisors if d >= n][0]
    print(m // small)


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


main()

Submission status: Accepted

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


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


ans = 0
for i in divisor(m):
    if n <= m // i:
        ans = i
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

#A,B=map(inr,input().split())
#a=list(map(int,input().split()))
from bisect import bisect_left as bl
from bisect import bisect_right as br
from math import log

from fractions import gcd
import sys
input=sys.stdin.readline

N,M=map(int,input().split())
def prime_factor(n):
    i = 2
    table = defaultdict(int)
    while i * i <= n:
        while n % i == 0:
            n //= i
            table[i]+=1
        i += 1
    if n > 1:
        table[n]+=1
    return table
table=prime_factor(M)
l=[1]
l_=[]
for i,j in table.items():
    for m in range(1,j+1):
        l_.extend([k*i**m for k in l])
    l.extend(l_)
    l_=[]
a=M
for L in l:
    if L>=N:
        a=min(a,L)
print(M//a)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
pf=[]
for i in range(1,int(m**0.5)+1):
    if m%i==0:
        pf.append(i);pf.append(m//i)
pf.sort(reverse=True)
ans=100000000
for i in pf:
  if i>=n:
    ans=i
print(m//ans)

Submission status: Accepted

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

def 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 = divisors(M)

for d in div :
    if M >= N * d :
        print(d)
        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 and m /n >= i:
        ans = max(ans,i)
        if i != m // i and m/n >= (m//i):
            ans = max(ans,m // i)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

st = set()
i = 1
while i * i <= m:
    if m % i == 0:
        st.add(i)
        st.add(m // i)
    i += 1

divs = tuple(sorted(st))
i = bisect_left(divs, n)
print(m // divs[i])