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:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7


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

    divisors.sort()
    return divisors
x,y=MI()
u=make_divisors(y)
for j in u:
    if j>=x:
        ans=y//j
        break
print(ans)

Submission status: Accepted

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

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

ans = 0
for i in sorted(diviser(M)):
  if i * N <= M:
    ans = max(ans, i)

print(ans)

Submission status: Accepted

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

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,M//i))
ans = 0
for x in L:
    if x[1] >= N:
        ans = max(ans,x[0])
    if x[0] >= N:
        ans = max(ans,x[1])
print(ans)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

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

Submission status: Accepted

Solution code:
# 解説AC

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

i=m//n

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

    divisors.sort(reverse=True)
    return divisors

lis=make_divisors(m)

for mm in lis:
    if mm<=i:
        ans=mm
        break

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n, m = Is()
a = m//n
for i in reversed(range(a+1)):
    if m % i != 0:
        continue
    else:
        print(i)
        exit()

Submission status: Accepted

Solution code:
def make_divisors(n):
    divisors = set([])
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.add(i)
            if i != n // i:
                divisors.add(n//i)
    return divisors
N,M = map(int,input().split())
A=make_divisors(M)
ans=0
for i in A:
 if i<=M/N:
  ans=max(ans,i)
print(ans)

Submission status: Accepted

Solution code:
import math
N,M = map(int, input().split())
#約数列挙
flag = True
yakusuu = []
for i in range(1, math.floor(math.sqrt(M))+1):
    if(M % i == 0):
        yakusuu.append(i)
        yakusuu.append(int(M / i))
yakusuu.sort()
yakusuu.reverse()
for i in yakusuu:
    if M / i >= N and flag == True:
        print(i)
        flag = False

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

D=make_divisors(M)
D=sorted(D)
ans=0
for d in D:
    if M//d>=N:
        ans=d
print(ans)

Submission status: Accepted

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

# 約数列挙

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

    upper_divisors.reverse()
    return lower_divisors + upper_divisors

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

box = make_divisors(m)

for i in range(len(box)):
  if box[i] >= n:
    print(m // box[i])
    exit()

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()
    divisors.reverse()
    return divisors
n, m = map(int, input().split())
l = make_divisors(m)
for i in l:
    if m / n >= i:
        print(i)
        exit()
print(1)

Submission status: Accepted

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

    return divisors


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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,m=map(int, input().split())
    def make_divisors(n):
             divisors = []
             for i in range(1, int(n**0.5)+1):
                 if n % i == 0:
                     # 約数の片割れをリストに
                     divisors.append(i)
                     # 平方数じゃなければ片割れの相方をリストに
                     if i != n // i:
                         divisors.append(n//i)
             divisors.sort(reverse=True) # sort必要なかったらコメントアウト
             return divisors
    for i in make_divisors(m):
        if i*n<=m:
            print(i)
            break

resolve()

Submission status: Accepted

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

P = [1]
for k in range(2,math.floor(math.sqrt(M))+1):
    if M % k == 0:
        P.append(k)
        P.append(M//k)

P = sorted(P)
for e in P:
    if e >= N:
        print(M//e)
        exit(0)
print(1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
i=1
x=[]
while(i*i<=m):
    if(m%i==0):
        x.append(i)
        x.append(m//i)
    i+=1
x.sort()
for xi in x:
    if(xi>=n):
        print(m//xi)
        break

Submission status: Accepted

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

n, m = [int(x) for x in input().split()]
ans = 0

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

    divisors.sort()
    return divisors

g = make_divisors(m)

for i in g:
    if m // i >= n:
        ans = i
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,K=pin()
    t=K//N
    for i in range(t,0,-1):
        if K%i==0:
            print(i)
            return
        
#%%submit!
resolve()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
# m の約数を求めるのです
i = 1
#import collections
#dic = collections.defaultdict(int)
li = []
while i*i <= m:
    if m % i == 0:
        if m//i != i:
            li.append(i)
            li.append(m//i)
        else:
            li.append(i)
    i += 1
#print(li)
# 最大の最大公倍数 N*d <= M
ans = 1
for v in li:
    if n*v <= m:
        ans = max(ans,v)
print(ans)

Submission status: Accepted

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

    def trial_division(n):
        divs = []
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divs.append(i)
                if i != n//i:
                    divs.append(n//i)
        divs.sort(reverse=True)
        return divs
    divs = trial_division(M)
    for d in divs:
        if d*N <= M:
            return print(d)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

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

N, M = map(int, input().split())
ds = make_divs(M)
ans = 0

for d in ds:
    if M//d>=N:
        ans = max(ans, d)

print(ans)

Submission status: Accepted

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

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

    divisors.sort(reverse=True)
    return divisors

d = make_divisors(m)
ans = -1
for i in d:
    j = m//i
    if j >= n:
        ans = max(i, ans)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

def factor(N):
    ans = []
    for i in range(1,int(np.sqrt(N))+1):
        if N%i == 0:
            ans.append(i)
            if N//i != i:
                ans.append(N//i)
    return ans

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def lcm(a, b):
    return (a * b)//gcd(a,b)

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

p.sort()

for i in reversed(range(len(p))):
    if p[i] <= M/N:
        print(p[i])
        break

Submission status: Accepted

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

n = M
# 約数列挙(1,N)も含まれる
prime, i = set(), 1
while i * i <= n:
    if n % i == 0:
        prime.add(i)
        prime.add(n//i)
    i += 1

ans = 1
l = list(prime)
for i in l:
    if i * N <= M:
        ans = max(ans, i)

print(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

for k in divisors(M):
    if k * N <= M:
        print(k)
        exit()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
def divisor(n):
  ass=[]
  for i in range(1,int(n**0.5)+1):
    if n%i==0:
      ass.append(i)
      if i!=n//i:ass.append(n//i)
  return ass
ans=0
for i in divisor(m):
  if m//i>=n:ans=max(ans,i)
print(ans)

Submission status: Accepted

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


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

A = divisors(m)

ans = 0
for a in A:
    if m // a >= n:
        ans = a

print(ans)

Submission status: Accepted

Solution code:
def main():
    N, M = (int(_) for _ in input().split())
    a = []
    output = 0
    for p in range(1, int(M**.5)+1):
        if M%p == 0:
            a.append(p)
            a.append(M//p)
    for p in a:
        if M//p >= N: output = max(output, p)
    print(output)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

    def divisor(n):
        ''' nの約数列挙 '''
        arr = []
        for i in range(1, int(n**0.5) + 1):
            if n % i == 0:
                arr.append(i)
                arr.append(n // i)
        return arr  # 戻り値はsortされていない

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

abc112_d()

Submission status: Accepted

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

syou = m//n
amari = m%n

while True:
    if amari%syou == 0:
        print(syou)
        break
    else:
        amari+=n
        syou-=1

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
import math
def divisor(n):
    a = set()
    for i in range(1, math.ceil(n**0.5) + 1):
        if n % i == 0:
            a.add(i)
            a.add(n // i)
    return a
d = list(divisor(m))
d.sort(reverse=True)
for di in d:
    if di * n <= m:
        print(di)
        exit()
print(1)

Submission status: Accepted

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

def f(m):
    d = []
    r = int(m**0.5)
    for i in range(1,r+1):
        if m % i == 0:
            d.append(i)
            d.append(m//i)
    d.sort(reverse = 1)
    return d

d = f(m)
for x in d:
    p = m//x
    #print(x,p)
    #if n <= p and p % n != 0:
    if n <= p:
        print(x)
        exit()

Submission status: Accepted

Solution code:

def divisor(n):
    ass = []
    for i in range(1, int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    return ass  # sortされていない


n, m = map(int, input().split())
m_div = divisor(m)
m_div.sort()
ans = 0
for i in m_div:
    if i * n <= m and (m - i*n) % i == 0:
        ans = max(ans, i)
print(ans)

Submission status: Accepted

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


def readstr():
    return input().strip()


def readint():
    return int(input())


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


def readstrs():
    return 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


def main():
    N, M = readnums()
    ml = make_divisors(M)
    print(max([x for x in ml if x <= M // N]))


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

Mlist = make_divisors(M)

ans = 0
for i in Mlist:
    if N * i <= M:
        ans = i
    else:
        break

print(ans)

Submission status: Accepted

Solution code:
def main():
    N, M = list(map(int, input().split(' ')))
    n = 1
    ans = 1
    while n**2 <= M:
        if M % n == 0:
            if n * N <= M:
                ans = max([ans, n])
            m = M // n
            if m * N <= M:
                ans = max([ans, m])
        n += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
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
def main():
    n,m=map(int,input().split())
    div=make_divisors(m)
    print(div[bisect.bisect(div,m//n)-1])
    

if __name__=='__main__':
    main()

Submission status: Accepted

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

n, m = map(int, input().split())
if n == 1:
    ans = m
else:
    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: Accepted

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: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, m = map(int, input().split())
print(next(v for v in range(m // n, -1, -1) if m % v == 0))

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
ps = [1]
nw = 1
mi = m//n
while nw**2 < m:
    if m%nw == 0:
        if mi >= nw:
            ps.append(nw)
        if mi >= m//nw:
            ps.append(m//nw)
    nw += 1
if nw**2 == m and nw <= mi:
    ps.append(nw)

print(max(ps))

Submission status: Accepted

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

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

d = M//N

divisor = sorted(make_divisors(M))

from bisect import *

b = bisect_left(divisor,d)
if divisor[b] == d:
  ans = divisor[b]
else:
  ans = divisor[b-1]
print(ans)

Submission status: Accepted

Solution code:
import math
from itertools import product
class Eratos:
    def __init__(self, num):
        assert(num >= 1)
        self.table_max = num
        # self.table[i] は i が素数かどうかを示す (bool)
        self.table = [False if i == 0 or i == 1 else True for i in range(num+1)]
        for i in range(2, int(math.sqrt(num)) + 1):
            if self.table[i]:
                for j in range(i ** 2, num + 1, i):    # i**2 からスタートすることで定数倍高速化できる
                    self.table[j] = False
        # self.table_max 以下の素数を列挙したリスト
        self.prime_numbers = [2] if self.table_max >= 2 else []
        for i in range(3, self.table_max + 1, 2):
            if self.table[i]:
                self.prime_numbers.append(i)
    
    def is_prime(self, num):
        """
        >>> e = Eratos(100)
        >>> [i for i in range(1, 101) if e.is_prime(i)]
        [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
        """
        assert(num >= 1)
        if num > self.table_max:
            raise ValueError('Eratos.is_prime(): exceed table_max({}). got {}'.format(self.table_max, num))
        return self.table[num]
    
    def prime_factorize(self, num):
        """
        >>> e = Eratos(10000)
        >>> e.prime_factorize(6552)
        {2: 3, 3: 2, 7: 1, 13: 1}
        """
        assert(num >= 1)
        if int(math.sqrt(num)) > self.table_max:
            raise ValueError('Eratos.prime_factorize(): exceed prime table size. got {}'.format(num))
        factorized_dict = dict()    # 素因数分解の結果を記録する辞書
        candidate_prime_numbers = [i for i in range(2, int(math.sqrt(num)) + 1) if self.is_prime(i)]
        # n について、√n 以下の素数で割り続けると最後には 1 or 素数となる
        # 背理法を考えれば自明 (残された数が √n より上の素数の積であると仮定。これは自明に n を超えるため矛盾)
        for p in candidate_prime_numbers:
            # これ以上調査は無意味
            if num == 1:
                break
            if num % p == 0:
                cnt = 0
                while num % p == 0:
                    num //= p
                    cnt += 1
                factorized_dict[p] = cnt
        if num != 1:
            factorized_dict[num] = 1
        return factorized_dict
    
    def enum_divisor(self, num):
        """
        >>> e = Eratos(10000)
        >>> e.enum_divisor(4)
        [1, 2, 4]
        >>> e.enum_divisor(19)
        [1, 19]
        >>> e.enum_divisor(100)
        [1, 5, 25, 2, 10, 50, 4, 20, 100]
        """
        factorized_dict = self.prime_factorize(num)
        primes = list(factorized_dict.keys())
        all_pattern_powers = product(*[range(i + 1) for i in factorized_dict.values()])    # 各素数を 0 to value 個まで任意回かけるとする。その全パターンを列挙
        divisor = []
        for power_pattern in all_pattern_powers:
            tmp = 1
            for i in range(len(power_pattern)):
                tmp *= pow(primes[i], power_pattern[i])
            divisor.append(tmp)
        return divisor

N, M = map(int, input().split())
eratos = Eratos(int(math.sqrt(M)) + 1)
L = eratos.enum_divisor(M)
L.sort(reverse=True)
for div in L:
    if div * N <= M:
        print(div)
        exit()

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(" "))
max = 1
#print(make_divisors(m))
for i in make_divisors(m):
  if i > m/n:
    break
  else:
    max = i
print(max)

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

dvs = make_divisors(m)

for item in dvs:
    if item >= n:
        print(m // item)
        exit()

Submission status: Accepted

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


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

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

if M%N == 0:
    print(M//N)
else:
    D = sorted(make_divisors(M))[::-1]
    for d in D:
        if M//d >= N:
            print(d)
            break

Submission status: Accepted

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

ans = 1
if(N < M//N):
  i = N
  while(ans == 1 and i <= math.sqrt(M)):
    if(M % i == 0):
      ans = M//i
    i += 1
if(N >= M//N or ans == 1):
  i = M//N
  while(ans == 1 and i >= 1):
    if(M % i == 0):
      ans = i
    i -= 1
  
print(ans)

Submission status: Accepted

Solution code:

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

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

a = 0
for x,y in ans:
    if x>=N:
        a = max(a, y)
    if y>=N:
        a = max(a, x)

print(a)

Submission status: Accepted

Solution code:
import sys
import bisect

inf = 10**15
mod = 10**9+7

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

    divisors.sort(reverse = True)
    return divisors


n,m = map(int, input().split())
kouho = make_divisors(m)
for num in kouho:
    if m//num >= n:
        print(num)
        sys.exit()

Submission status: Accepted

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

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

    divisors.sort()
    return divisors

test=make_divisors(m,n)
print(m//min(test))

Submission status: Accepted

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

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

def main():
    N, M = map(int, readline().rstrip().split())
    ans = 1
    for d in  make_divisors(M):
        if M // d >= N:
            ans = d
        else:
            break

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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


def make_divisors(n):
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            yield i
            if i != n // i:
                yield n // i


ans = 0
for x in make_divisors(M):
    if x >= N:
        ans = max(ans, M // x)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = [int(elem) for elem in 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 = sorted(divisors)
for i in range(len(divisors), 0, -1):
  if m/n >= divisors[i-1]:
    print(divisors[i-1])
    break

Submission status: Accepted

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

Submission status: Accepted

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

N, M = map(int, input().split())
from fractions import gcd

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

def main():
    x = M // N
    divisors = sorted(make_divisors(M))
    ok = 0
    ng = len(divisors) - 1
    if divisors[ng] <= x:
        print(divisors[ng])
        exit()
    while ok + 1 < ng:
        c = (ok + ng) // 2
        if divisors[c] <= x:
            ok = c
        else:
            ng = c
    print(divisors[ok])

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())
divisors=make_divisors(M)
ans=0
for d in divisors:
    if N*d<=M:
        ans=d
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

i = 1
ans = 0
while i * i <= M:
    if M % i == 0 and M // i >= N:
        ans = max(ans, i)
    if M % i == 0 and M // (M // i) >= N:
        ans = max(ans, M // i)

    i += 1

print(ans)

Submission status: Accepted

Solution code:
import heapq

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

lst = []
nf = M

for i in range(1, int(M**0.5 + 1)):
    if nf % i == 0:
        lst.append(-i)
        if i * i != nf: lst.append(-nf//i)

heapq.heapify(lst)
while lst:
    hq = -heapq.heappop(lst)
    if M // hq >= N:
        break
print(hq)

Submission status: Accepted

Solution code:
def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    return ass

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

divisors = divisor(M)

ans = 1
divisors.sort()

for d in divisors:
  if N*d <= M:
    ans = d

print(ans)

Submission status: Accepted

Solution code:
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    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: # 平方数の場合n**0.5を1つだけにしてる
                    divisors.append(n//i)

        divisors.sort(reverse=True) # ソートしたけりゃして
        return divisors
    l=make_divisors(m)
    for i in l:
        if n*i<=m:
            print(i)
            break



resolve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon May  4 20:38:08 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

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

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

    divisors.sort()
    return divisors

divisors = make_divisors(M)

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

Submission status: Accepted

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

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

div = divisible(M)

div = [d for d in div if d <= M / N]

print(max(div))

Submission status: Accepted

Solution code:

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

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

divisors = divisor(M)

ans = 1
divisors.sort()

for d in divisors:
  if N*d <= M:
    ans = d

print(ans)