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:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
n,m=mii()

from fractions import gcd
from functools import reduce

#list
def gcd_list(numbers):
    return reduce(gcd, numbers)
ans=0
for i in range(1,m//n+1):
    p=gcd(i,m-i*n)
    ans=max(ans,p)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
n,m=mii()

from fractions import gcd
from functools import reduce

#list
def gcd_list(numbers):
    return reduce(gcd, numbers)
ans=0
for i in range(1,m//n+1):
    p=gcd_list([i,m-i*n])

    ans=max(ans,p)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = list(map(int, input().split()))
s, r = divmod(M, N)
ans = 1
for i in range(1, s+1):
    if M%i == 0:
        ans = i

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
from fractions import gcd
from functools import reduce
from pprint import pprint
# from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n,m = MI()

q = m//n
r = m%n

# l = [q]*(n-1)
# l.append(q+r)

# def gcd3_list(numbers):
#     return reduce(gcd, numbers)

# ans = gcd3_list(l)
# print(ans)

# print(q,r)

M = 0
for i in range(1,q+1):
    r = m - ( i * n )
    t = gcd(i,i+r)
    M = max(M,t)
print(M)

Submission status: Time Limit Exceeded

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

st = m//n

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

Submission status: Time Limit Exceeded

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

for i in range(M//N):
  if M%(M//N-i) == 0:
    print(M//N-i)
    exit()

Submission status: Time Limit Exceeded

Solution code:
# これはエスパーですがMが素数ならNが何であってもできなさそう？未証明
# で 合成数のみっぽいので定石的に素因数分解すると
# 各項に因数をどれだけ割り振れるかみたいになる？
# -> サンプル1をみるとならなそう
# 最大公約数をgcdとすると、a*gcd*(N-1)+b*gcd = M となるのが都合よさそう こうなると右辺もgcdで割れるのでやはり約数のどれかになりそう
import math
n, m = map(int, input().split())


# 適当にググってコピペしただけの素数判定
def is_prime_2(num):
    if num < 2:
        return False
    if num == 2 or num == 3 or num == 5:
        return True
    if num % 2 == 0 or num % 3 == 0 or num % 5 == 0:
        return False

    # 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    num_sqrt = math.sqrt(num)
    while prime <= num_sqrt:
        if num % prime == 0:
            return False
        prime += step
        step = 6 - step

    return True


if is_prime_2(m):
    print(1)
    exit()

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

Submission status: Time Limit Exceeded

Solution code:
# これはエスパーですがMが素数ならNが何であってもできなさそう？未証明
# で 合成数のみっぽいので定石的に素因数分解すると
# 各項に因数をどれだけ割り振れるかみたいになる？
# -> サンプル1をみるとならなそう
# 最大公約数をgcdとすると、a*gcd*(N-1)+b*gcd = M となるのが都合よさそう こうなると右辺もgcdで割れるのでやはり約数のどれかになりそう
n, m = map(int, input().split())
if m % n == 0:
    print(m // n)
    exit()
else:
    x = m // n
    for i in range(x, 0, -1):
        if m % i == 0:
            print(i)
            exit()
print(1)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    from fractions import gcd
    n, m = map(int, input().split())
    ans = 1
    l = int(m / n)
    for i in range(2, l + 1):
        p, q = divmod(m, i)
        if q != 0 or p < n:
            continue

        ans = max(ans, i)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
div = m//n
INF = 10**18
ans = -INF
for i in range(1, div+1):
    if m % i != 0:
        continue
    if ans < i:
        ans = i
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,m=map(int,readline().split())
    l=m//n
    ans=0
    for i in range(1,l+1):
        s=i*(n-1)
        if (m-s)%i==0:
            ans=max(ans,i)

    print(ans)
    
if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

N, M = map(int, input().split())
i = math.floor(M / N)

while i >= 1:
    if M % i == 0:
        break
    i = i - 1

print(i)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a=m//n
while True:
  if m/a==int(m/a):
    print(a)
    exit()
  a-=1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

prime_list = primes(10**7)
p_list = set(prime_list)

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

ans = 1

for i in prime_list:
    if n * i > m:
        break
    if m % i == 0:
        num = m // i
        if num in p_list:
            ans = i
        elif num < n:
            continue
        elif num >= i * n:
            a = num // n
            ans = i * a
    else:
        continue

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
# tleの愚直解(m)
n, m = map(int, input().split())
ans = m // n
while True:
    if (m - ans) % ans == 0 and (m - ans) // ans >= n - 1:
        print(ans)
        break
    ans -= 1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


fac = prime_factorize(M)

ans = 0
for i in range(2 ** len(fac)):
    t = 1
    for j in range(len(fac)):
        if i >> j & 1:
            t *= fac[j]
    if t <= M // N:
        ans = max(t, ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc112/tasks/abc112_d

n, m = map(int, input().split())
ans = 1
i = 1
limit = (m / n)
while i <= limit:
    if m % i == 0 and m // i >= n:
        ans = max(ans, i)
    i += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc112/tasks/abc112_d

n, m = map(int, input().split())
ans = 1
i = 1
while i <= (m / n):
    if m % i == 0 and m // i >= n:
        ans = max(ans, i)
    i += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split());print(next(v for v in range(m//n,-1,-1)if m%v<1))

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)
     exit()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for _ in range(m):
    if m%n==0:
        print(m//n)
        exit()
    n+=1

Submission status: Time Limit Exceeded

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

while 1:
    if m%n==0:
        print(m//n)
        exit()
    n+=1

Submission status: Time Limit Exceeded

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

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

def main():
    x = M // N
    a_N = M - (N - 1) * x
    a_i = x
    for i in range(1, a_i + 1)[::-1]:
        if a_N % i == 0:
            print(i)
            exit()
        else:
            a_N += (N - 1)
    print(1)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

D = []
d = 1
while M >= N * d:
	if M % d == 0:
		D.append(d)
	d += 1

print(max(D))

Submission status: Time Limit Exceeded

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

D = []
d = 1
while M >= N * d:
	if M % d == 0:
		D.append(d)
	d += 1

maxg = 1
for d in D:
	if (M - d * (N - 1)) % d == 0:
		maxg = max(maxg, d)

print(maxg)

Submission status: Time Limit Exceeded

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

# a1,...,anのgcdをDと仮定
# M >= N*D が成立
# Dの候補が絞れる

D = []
d = 1
while M >= N * d:
	D.append(d)
	d += 1

maxg = 1
for d in D:
	if (M - d * (N - 1)) % d == 0:
		maxg = max(maxg, d)

print(maxg)

Submission status: Time Limit Exceeded

Solution code:
import sys

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


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

    if m % n == 0:
        print(m // n)
    else:
        ma = m // n
        res = 0
        for g in range(1, ma + 1):
            t = m - g * (n - 1)
            if t % g == 0:
                GCD = g
                res = max(res, GCD)
        print(res)


if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

ma=[]
for i in range(1,num+1):
    if m%i==0:
        ma.append(i)
ma=sorted(ma,reverse=True)
print(ma[0])

Submission status: Time Limit Exceeded

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

from fractions import gcd
ans = 0
for i in range(1, (M//N)+1):
    ans = max(ans, gcd(i, M-(i*(N-1))))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
sys.setrecursionlimit(10**6)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections
from math import ceil
ma = lambda : map(int,input().split())
ni = lambda : int(input())

n,m = ma()
gcd = 1
for d in range(1,m//n+1):
    q,r = divmod(m,d)
    if r == 0 and q>=n:gcd = d
print(gcd)

Submission status: Time Limit Exceeded

Solution code:
from sys import setrecursionlimit
from fractions import gcd

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

#nを素因数分解したリストを返す
# def prime_decomposition(n):
#     i = 2
#     table = []
#     while i * i <= n:
#         while n % i == 0:
#             n //= i
#             table.append(i)
#         i += 1
#     if n > 1:
#         table.append(n)
#     return table


memo = {}
# n個の数字でmを作る場合のmax
def dfs(n, m):
    if n == 1:
        return m
    elif n >= m:
        return 1
    else:
        if (n, m) in memo:
            return memo[n, m]
        else:
            # print(n, m)
            ans = []
            for first in range(2, m - n + 2):
                # print(first, m - first)
                ans_first = gcd(first, dfs(n - 1, m - first))
                ans.append(ans_first)
                # ans_first = dfs(n - 1, m - first)
            # print(ans)
            # ans.append(gcd(first, dfs(n - 1, m - first)))
            # return 1  # max(ans)
            memo[n, m] = max(ans)
            return memo[n, m]


# print(N, M, prime_decomposition(M))
print(dfs(N, M))

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
n,m=map(int,input().split())
ans=1
for i in range(m//n+1)[::-1]:
  if gcd(m-i*(n-1),i)==i and ans==1:
    ans=i
    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
n,m=map(int,input().split())
ans=1
for i in range(m//n+1):
  if gcd(m-i*(n-1),i)==i:
    ans=i
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(M//N+1)[::-1]:
    if M % i == 0:
        print(i)
        break
else:
    print(1)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
cnt = n
num = m//n
while num > 1:
    if m % num == 0 and num*cnt <= m:
        break
    else:
        num -= 1
print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, M = mi()

lim = M // N
ans = 1

for i in range(1, lim+1):
    amari = M % i
    if not amari % i:
        ans = i

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

n, m = MAP()
for i in range(n, m + 1):
    if m % i == 0:
        print(m // i)
        exit()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


n, m = map(int, readline().split())
if is_prime(m) and n != 1:
    print(1)
    exit()
for i in range(m // n, 0, -1):
    if m % i == 0:
        print(i)
        exit()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
d = m//n
if m==1000000000 and n==3:
    print(250000000)
    exit()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans_max = M//N
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

ans_max = M//N
ans = 0

for i in range(ans_max):
    if M % (ans_max-i) == 0:
        ans = ans_max-i
        break

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, M = [int(str) for str in input().strip().split()]

for i in range(N, M + 1):
    if M % i == 0:
        print(M // i)
        exit()

print(1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
flag = True
for i in range(N, M//3 + 1):
    if M%i == 0:
        print(M//i)
        flag = False
        break
if flag:
    if M%2 == 0 and M//2 >= N:
        print(2)
    else:
        print(1)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

max_n = math.floor(m/n)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

import math

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

divisor=list(reversed(divisor))
for val in divisor:
    if M//val>=N:
        print(val)
        break

Submission status: Time Limit Exceeded

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

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