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: Time Limit Exceeded

Solution code:
[n,m] = [int(i) for i in input().split()]
a=[]
for i in range(1,m//n+1):
    if m % i == 0 and i <= m//n:
        a.append(i)

print(a[len(a)-1])

Submission status: Time Limit Exceeded

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

X = M // N
for x in range(X, 1, -1):
    r = M - x * (N - 1)
    if r % x == 0:
        print(x)
        exit()
print(1)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

re = 1
for i in range(1, M):
    if M % i == 0:
        a = M // i
        if a >= N:
            re = i
        else:
            break
print(re)

Submission status: Time Limit Exceeded

Solution code:
ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]


n,m = ai()

for k in range(m,0,-1):
    if m/k == m//k and m//k >= n:
        print(k)
        exit()
print(1)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
[n,m] = [int(i) for i in input().split()]
a=[]


for i in range(1,m//n+1):
    if m % i == 0:
        a.append(i)
#print(a)
a.sort(reverse=True)
#print(a)
for i in a:
    if i <= m//n:
        print(i)
        break

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def run():
	N, M = (int(x) for x in input().split())
	i = 2
	result = 1

	while True:
		if M % i == 0 and N * i <= M:
			result = i

		i += 1
		if i * N > M:
			break

	print(result)



if __name__ == '__main__':
	run()

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None

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

    x = M // N
    ans = -1

    if N == 1:
        print(M)
        return

    for i in range(x, 0, -1):
        j = M - (i * (N - 1))

        ans = max(ans, gcd(i, j))

        if i - 1 < ans:
            break

    print(ans)

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None

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

    x = M // N
    ans = -1

    for i in range(x, 0, -1):
        a = i
        b = M - (i * (N - 1))

        ans = max(ans, gcd(a, b))

        if i - 1 < ans:
            break

    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt
n,m = (int(i) for i in input().split())
f = 1
for i in range(2,int(sqrt(m))+1):
	if m%i==0:
		f = 0
		break
if f: print(1)
else:
	for i in range(m//n,0,-1):
		if m%i==0: break
	print(i)

Submission status: Time Limit Exceeded

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: Time Limit Exceeded

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None

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

    x = M // N
    ans = -1

    for i in range(x, 0, -1):
        a = i
        b = M - (i * (N - 1))

        ans = max(ans, gcd(a, b))

    print(ans)

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
print(max(n for n in range(1, M // N + 1) if M % n == 0))

Submission status: Time Limit Exceeded

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

q = m // n
for i in range(q):
    p = q - i
    r = m % p
    if r == 0:
        print(p)
        exit()

Submission status: Time Limit Exceeded

Solution code:
import sys
N,M = map(int, input().split())
tmax = int(M/N)
t = tmax
while 1 == 1:
  if M%t==0:
    print(t)
    sys.exit()
  t += -1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import itertools
# import math
# from functools import reduce
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
N, M = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

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

# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)

# if gcd_list(A) > 1:
#     print("not coprime")
#     exit()

# 高速素因数分解準備
#MAXN = 10**6+10
#sieve = [i for i in range(MAXN+1)]
#p = 2
#while p*p <= MAXN:
#    if sieve[p] == p:
#        for q in range(2*p, MAXN+1, p):
#            if sieve[q] == q:
#                sieve[q] = p
#    p += 1

l = make_divisors(M)

# print(l)

threshold = M / N

for i, d in enumerate(l):
    if threshold < d:
        print(l[i - 1])
        exit()

print(M)

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())
h = m // n
ans = 0

for d in make_divisors(m):
    if d <= h:
        ans = max(ans, d)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque

def divisor(x):
    """約数"""
    from math import floor
    re = []
    _x = floor(x ** 0.5)
    for i in range(1, _x + 1):
        if x % i == 0:
            re.append(i)
            if x // i != i:
                re.append(x // i)
    re.sort()
    return re


# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, M):
    div = divisor(M)
    div.sort()
    ans = 0
    for d in div:
        if M // d >= N:
            ans = d
    print(ans)


if __name__ == '__main__':
    # S = input()
    # N = int(input())
    N, M = map(int, input().split())
    # A = [int(i) for i in input().split()]
    # B = [int(i) for i in input().split()]
    # AB = [[int(i) for i in input().split()] for _ in range(N)]
    solve(N, M)

    # # test
    # from random import randint
    # from func import random_str
    # solve()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
nums = []
for n in range(1, int(M**0.5)+1):
  if M%n == 0:
    nums.append(n)
    nums.append(M//n)
nums.sort()
answer = 1
for num in nums:
  if M//num < N:
    break
  else:
    answer = num
print(answer)

Submission status: Accepted

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

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

for d in div:
  if d <= m/n:
    ans = d
print(ans)

Submission status: Accepted

Solution code:
import math

def main():
	N, M = [int(a) for a in input().split(" ")]
	divM = []
	for i in range(1, int(math.sqrt(M)) + 1):
		if M % i == 0:
			divM += [i, M // i]
	divM.sort()
	divM = list(filter(lambda m: m >= N, divM))
	print(M // divM[0])

main()

Submission status: Accepted

Solution code:
import bisect
N,M=map(int,input().split())
divd=[]
i=1
while i*i<=M:
    if M%i==0:
        divd.append(i)
        if i!=M//i:
            divd.append(M//i)
    i+=1
divd.sort()
k=bisect.bisect_left(divd,N)
print(M//divd[k])

Submission status: Accepted

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

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)
divisors.sort()

print([i for i in divisors if i <= m/n][-1])

Submission status: Accepted

Solution code:
import bisect
def enum_devisors(n):
    divisors = set([])
    for i in range(1, int(n**.5) + 1):
        if n%i == 0:
            divisors.add(i)
            divisors.add(n//i)
    return divisors

n,m = list(map(int, input().split()))
devisors = sorted(enum_devisors(m))
d = devisors[bisect.bisect_left(devisors, n)]
print(m//d)

Submission status: Accepted

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

yakusuu=[]
import math
for i in range(1,int(math.sqrt(m)+1)):
  if m%i==0:
    yakusuu.append(i)
    yakusuu.append(m//i)
yakusuu.sort()
for num in yakusuu:
  if num>=n:
    print(m//num)
    exit()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
for i in range(n,10**8):
  if m%i==0:
    print(m//i)
    exit()
print(1)

Submission status: Accepted

Solution code:
import sys
# sys.setrecursionlimit(100000)


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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, m = input_int_list()
    max_gcd = m // n
    while max_gcd > 1:
        if (m - max_gcd) % max_gcd == 0 and (m - max_gcd) // max_gcd >= n - 1:
            print(max_gcd)
            return
        else:
            max_gcd -= 1
    print(1)
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

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

    return return_list

def main():
    n, m = i_map()

    divisors_list = make_divisors(m)

    divisors_list.sort(reverse=True)

    for num in divisors_list:
        if num <= m / n:
            print(num)
            exit()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
k, s = list(map(int, input().split()))

p = s
factors = {}

while p > 1:
    f = False
    for i in range(2, int(p**0.5)+1):
        if p % i == 0:
            if i in factors:
                factors[i] += 1
            else:
                factors[i] = 1

            p //= i
            f = True
            break

    if not f:
        if p in factors:
            factors[p] += 1
        else:
            factors[p] = 1
        break

if len(factors) == 0:
    print(1)
else:
    primes = list(factors.keys())
    exp = [0] * len(primes)
    upper = s/k
    ans = 1

    while exp[0] <= factors[primes[0]]:
        num = 1
        for i in range(len(primes)):
            num *= pow(primes[i], exp[i])

        if num == upper:
            ans = num
            break
        elif num < upper:
            ans = max(ans, num)

        index = len(primes)-1
        done = False
        while not done:
            exp[index] += 1
            if exp[index] > factors[primes[index]]:
                if index == 0:
                    break
                else:
                    exp[index] = 0
                    index -= 1
            else:
                done = True

    print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

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

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy
from operator import itemgetter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

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

N, M = na()
MAX = M // N
ans = 1

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

if M % N == 0:
    print(M // N)
else:
    tmp = make_divisors(M)
    print(tmp[max(bisect.bisect_left(tmp, MAX) - 1, 0)])

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = m//n
di = []
for i in range(1, min(a+1,int(m**0.5)+1)):
  if m % i == 0:
    di.append(i)
    if i != m // i and a >=  m // i:
      di.append(m//i)
di.sort()
print(di[-1])

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
p=[]
pp=[]
for i in range(1,int(m**0.5)+1):
  if m%i==0:
    p.append(i)
    pp.append(m//i)
pp.reverse()
p+=pp
l,r=-1,len(p)
while r-l!=1:
  t=(l+r)//2
  if p[t]>=n:
    r=t
  else:
    l=t
print(m//p[r])

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from copy import copy, deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

N,M=mint()
P=pf(M,mode='list')
i=bisect_right(P,M//N)
print(P[i-1])

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


def main():
    N, M = map(int, input().split())
    ass = divisor(M)
    ass.sort()
    ans = 1
    for a in ass:
        if a <= (M // N):
            ass = a
        else:
            print(ass)
            exit()
    print(ass)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
n, m = map(int, input().split())
fact = []
ans = 1
MAX = int(math.sqrt(m)) + 1
for i in range(1, MAX):
    if m % i == 0:
        fact.append(i)
        if i != m // i:
            fact.append(m//i)
fact.sort()
for x in fact:
    if m < n * x:
        break
    ans = x
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

# 約数列挙
def enum_div(N):
    ret = []
    for i in range(1,int(N**0.5)+1):
        if N % i == 0:
            ret.append(i)
            if i**2 != N:
                ret.append(N // i)
        i += 1
    return ret

ans = 0
for i in enum_div(M):
    if i >= N:
        ans = max(ans,M // i)

print(int(ans))

Submission status: Accepted

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

# 約数列挙
def enum_div(N):
    ret = []
    i = 1
    while True:
        if i**2 > N:
            break
        if N % i == 0:
            ret.append(i)
            if i**2 != N:
                ret.append(N / i)
        i += 1
    return ret

ans = 0
for i in enum_div(M):
    if i >= N:
        ans = max(ans,M / i)

print(int(ans))

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:
from math import sqrt
from math import floor
n,m = map(int,input().split())
d = m // n
ans = 1
for i in range(1,floor(sqrt(m))+1):
    if m % i == 0:
        x = m // i
        if i <= d:
            ans = max(ans,i)
        if x <= d:
            ans = max(ans,x)
print(ans)

Submission status: Accepted

Solution code:
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, M = read_ints()
    # M = a*b b >= N
    i = 1
    max_gcd = 1
    while i*i <= M:
        if M%i == 0:
            if M//i >= N:
                max_gcd = max(max_gcd, i)
            if i >= N:
                max_gcd = max(max_gcd, M//i)
        i += 1
    return max_gcd


if __name__ == '__main__':
    print(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)

    divisors.sort()
    return divisors


b = make_divisors(m)
# print(b)
a = m//n
# print(a)
ans = 0
for i in b:
    if i <= a:
        ans = i
print(ans)

Submission status: Accepted

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

while gcd*N!=M:
  gcd = M//N
  N = 1+(M-1)//gcd

print(gcd)