Problem:


Score : 400 points

Problem Statement

You are given integers N and M.

Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

N \leq M \leq 10^9

Input

Input is given from Standard Input in the following format:

N M

Output

Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition.

Sample Input 1

3 14

Sample Output 1

2

Consider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common divisor is 2, and this is the maximum value.

Sample Input 2

10 123

Sample Output 2

3

Sample Input 3

100000 1000000000

Sample Output 3

10000



Sample input:
3 14


Sample output:
2

Submission status: Accepted

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

def make_divisors(n):
    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]
  
a=make_divisors(m)

ans=[]

for i in a:
  if m//i>=n:
    ans.append(i)
    
print(max(ans))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ans = 1
if N == 1:
    print(M)
else:
    for n in range(2, int(M ** 0.5) + 1):
        if M % n == 0 and M / N >= n:
            ans = max(ans, n)
            if M // n * N <= M:
                ans = max(ans, M // n)
    print(ans)

Submission status: Accepted

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

f=[]
for m in range(1,int(M**(1/2))+3):
    if M % m == 0:
        f.extend([m,M//m])
f.sort(reverse=True)

for f_ in f:
    if N <= M/f_:
        ans=f_
        break
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[11]:


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


# In[12]:


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]


# In[14]:


for x in make_divisors(M)[::-1]:
    if M//x >= N:
        ans = x
        break
print(ans)


# In[ ]:

Submission status: Accepted

Solution code:
N,M=map(int, input().split())
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]
A=make_divisors(M)
for i in range(len(A)):
  if A[i]>=N:
    print(A[-1-i])
    exit()

Submission status: Accepted

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

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

d=primes(M)

for i in d[::-1]:
    if M//i>=N:
        ans=i
        break

print(ans)

Submission status: Accepted

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

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


A = make_divisors(M)
for an, a in zip(A, A[1:]):
    ans = an
    if a * N > M:
        break
else:
    ans = M
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
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]
D = sorted(make_divisors(M))[::-1]

for e in D:
    if N*e <= M:
        print(e)
        exit(0)

Submission status: Accepted

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

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

Submission status: Accepted

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


N, M = map(int, input().split())
divs = sorted(enum_divisors(M), reverse=True)
ans = max(d for d in divs if M // d >= N)
print(ans)

Submission status: Accepted

Solution code:
def LI():
    return list(map(int, input().split()))


N, M = LI()
x = M//N
for i in range(x, 0, -1):
    if M % i != 0:
        continue
    ans = i
    break
print(ans)

Submission status: Accepted

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

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

    # divisors.sort()
    return divisors

ans = 1
for i in make_divisors(M):
    work1 = i * N
    work2 = M - work1
    if work2 >= 0 and work2 % i == 0:
        ans = max(i, ans)
# print(make_divisors(M))
print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n,m = readInts()
def yaku(m):
        ans = []
        i = 1
        while i*i <= m:
            if m % i == 0:
                j = m // i
                ans.append(i)
                if j != i:
                    ans.append(j)
            i += 1
        ans = sorted(ans)
        return ans
dic = yaku(m)
ans = 1
for k in dic:
    if k*n <= m:
        ans = max(ans,k)
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
amax = 1
for i in range(1,int(M**0.5)+1):
    if M%i==0:
        b = i
        c = M//i
        if b>=N and c>=N:
            a = max(b,c)
        elif c<N<=b:
            a = c
        elif b<N<=c:
            a = b
        else:
            a = 1
        amax = max(amax,a)
print(amax)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

ans = 0
i = 1
while i * i <= m:
    if m % i == 0:
        a, b = i, m // i
        if b >= n:
            ans = max(ans, a)
        if a >= n:
            ans = max(ans, b)
    i += 1
print(ans)

Submission status: Accepted

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

ans = 1
for i in range(1,10**5):
    if m%i == 0:
        v = i
        cnt = m//i
        if cnt >= n:
            ans = max(ans,v)

        v = m//i
        cnt = i
        if cnt >= n:
            ans = max(ans,v)

print(ans)

Submission status: Accepted

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

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

    divisors.sort()
    return divisors

lst=make_divisors(m)

for i in lst:
    if i>=n:
        print(m//i)
        exit()

Submission status: Accepted

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

P=[]
A=round(M**0.5)+2
for i in range(1,A):
    if M%i==0:
        P.append(i)
        P.append(M//i)
P.sort()

B=M//N
ans=now=1
for p in P:
    now=p
    if now<=B:
        ans=now
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

x = m //n
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]

y = make_divisors(m)

res = 1

for i in y:
    if i <=x:
        res = i
        
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

print(max(filter(lambda x: x <= M // N, divisor)))

Submission status: Accepted

Solution code:

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

if M % N == 0:
    print(M // N)
else:
    ans = 1
    for n in range(1, M // N + 1):
        res = M - n * N
        if res % n == 0:
            ans = n

    print(ans)

Submission status: Accepted

Solution code:
# 1 <= N <= 10**5
# N <= M <= 10**9
import sys
input = sys.stdin.buffer.readline
N, M = map(int, input().split())

V = M // N

ans = 1
for i in range(1, V + 1):
    if i * i > M:
        break
    if M % i == 0:
        j = M // i
        if j <= V:
            ans = max(ans, j)
        else:
            ans = max(ans, i)
print(ans)

Submission status: Accepted

Solution code:
import sys, math
from functools import lru_cache
from collections import deque
from bisect import bisect_left
sys.setrecursionlimit(10**9)

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


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

    d = []
    i = 1
    while i*i <= M:
        if M%i == 0:
            d.append(i)
            d.append(M//i)
        i += 1

    d.sort()

    for v in d:
        if v <= M//N:
            ans = v
        else:
            break

    print(ans)

    



if __name__ == '__main__':
    main()

Submission status: Accepted

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

l = []
for i in range(1, int(math.sqrt(M))+1):
  if M % i == 0:
    l.append(i)
    if i != M//i:
      l.append(M//i)
      
l.sort(reverse=True)
for n in l:
  if n*N <= M:
    ans = n
    break
print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = list(map(int, input().split()))
ans = -1
for i in range(1,m+1):
    if i*i>m+10:
        break
    if m%i==0:
        if m//i>=n:
            ans = max(ans, i)
        if i>=n:
            ans = max(ans, m//i)
print(ans)

Submission status: Accepted

Solution code:
### ABC112D Partition Diff:

N, M = map(int, input().split())
from math import sqrt

def divisor(num):
    max_num = int(sqrt(num))
    divisor_list = []
    for i in range(1, max_num + 1):
        if num % i == 0:
            divisor_list.append(i)
            divisor_list.append(num//i)
    return divisor_list

div = divisor(M)
div.sort(reverse=True)
ans = None
for g in div:
    if N > M//g:
        continue
    ans = g
    break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


def read():
    N, M = map(int, input().strip().split())
    return N, M


def divisor(n):
    divisors = []
    i = 1
    while i * i <= n:
        if n % i == 0:
            divisors.append(i)
            if i * i != n:
                divisors.append(n // i)
        i += 1
    return list(sorted(divisors))


def solve(N, M):
    D = divisor(M)
    ans = 1
    for p in D:
        n = M // p
        if n >= N:
            ans = max(ans, p)
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def divisors(n):
    i = 1
    table = set()
    while i * i <= n:
        if not n % i:
            table.add(i)
            table.add(n//i)
        i += 1
    table = list(table)
    return table
from bisect import *
N, M = map(int, input().split())
A = divisors(M)
A.sort()
print(M//A[bisect_left(A,N)])

Submission status: Accepted

Solution code:
from bisect import bisect_left,bisect

# ===================================== 約数のリスト   
def enum_div(n):
    ir=int(n**(0.5))+1
    ret=[]
    for i in range(1,ir):
        if n%i == 0:
            ret.append(i)
            if (i!= 1) & (i*i != n):
                ret.append(n//i)
    return ret

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

div=enum_div(m)+[m]
div.sort(reverse=True)

rd=[0]*len(div)
for i in range(len(div)):
    rd[i]=m//div[i]

mm=bisect_left(rd,n)

print(div[mm])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
#mの約数を調べる
temp=[]
i=1
while i*i<=m:
    if m%i==0:
        temp.append(i)
        if m//i!=i:
            temp.append(m//i)
    i+=1
temp.sort()
for i in temp:
    if i>=n:
        print(m//i)
        break

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

Submission status: Accepted

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

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]

l = make_divisors(m)

l.reverse()


for x in l:
    if m // x >= n:
        print(x)
        break

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
def make_divisors(n):
    divisors = []
    # 試し割りで、かつ積でnを作るときの相方も同時に追加してる
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
div_ls = make_divisors(M)
ans = 1
for div in div_ls:
    if div*N <= M:
        ans = max(ans,div)
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt

def f(x):
    divisors = [[], []]
    for i in range(1, int(sqrt(x))+1):
        if x % i == 0:
            divisors[0].append(i)
            if i * i != x:
                divisors[1].append(x//i)
    return divisors[0] + divisors[1][::-1]

n, m = map(int, input().split())
for i in f(m):
    if n <= i:
        print(m//i)
        exit()

Submission status: Accepted

Solution code:
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

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

if m%n==0:
    print(m//n)
else:
    arr = sorted(divisor(m))
    # print(arr)
    for i in arr:
        if i >= n:           
            print(m//i)
            exit()

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
#最大公約数のバリエーションは高々M種類？
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]

#約数は奇数個or偶数個
for i in reversed(make_divisors(M)):
    if M//i<N:
        pass
    else:
        print(i)
        exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, m = map(int, input().split())
for i in reversed(range(1,m//n+1)):
    if m%i<1:
        print(i)
        exit()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ls = []
for i in range(1,int(m**(1/2))+1):
    if m % i == 0:
        ls.append(i)
        ls.append(m//i)
ls = sorted(list(set(ls)),reverse=True)
for j in ls:
    if j*n <= m:
        print(j)
        break

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

    lower.extend(reversed(upper))
    return lower


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

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def divisor(num):
    max_num = int(sqrt(num))
    divisor_list = []
    for i in range(1, max_num + 1):
        if num % i == 0:
            divisor_list.append(i)
            divisor_list.append(num//i)
    return divisor_list

g_list = divisor(M)
g_list.sort(reverse=True)
ans = 0
for g in g_list:
    if M//g >= N:
        ans = g
        break
print(ans)

Submission status: Accepted

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

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 sorted(lower_divisors + upper_divisors[::-1],reverse=True)

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

Submission status: Accepted

Solution code:
import sys


read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def 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 main():
    N, M = map(int, readline().split())
    M_div = divisors(M)
    for div in M_div:
        if div>=N:
            print(M//div)
            break




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
t=int(m/n)
while True:
    if m%t==0:
        if t*n<=m:
            print(t)
            exit()
        else:
            t-=1
    else:
        t-=1

Submission status: Accepted

Solution code:
from functools import reduce

def factors(n):
    return set(reduce(list.__add__,
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))


n,m=map(int,input().strip().split(" "))
fact=sorted(factors(m),reverse=True)
ans=1
for i in fact:
    if m//i >=n:
        ans=i
        break
print(ans)

Submission status: Accepted

Solution code:
import math
n,m=map(int,input().split())
ans=list()
for i in range(1,int(math.sqrt(m))+1):
  if m%i==0:
    ans.append(i)
    ans.append(m//i)
ans.sort(reverse=True)
for x in ans:
  if x <= m//n:
    print(x)
    break

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    maxM = M//N + 1
    for m in range(maxM, 0, -1):
        tmp = m * N
        remain = M - tmp
        check = remain % m
        if check == 0 and remain >= 0:
            print(m)
            return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ans=0
for i in range(1,int(m**0.5)+1):
  if m%i>0:continue
  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=map(int,input().split())
yakusuu=[]
for i in range(1,int(m**0.5)+1):
  if m%i==0:
    yakusuu.append(m//i)
    if m//i==i:continue
    yakusuu.append(i)
ans=0
for y in yakusuu:
  if y<n:continue
  if m%y==0:
    ans=max(ans,m//y)
print(ans)

Submission status: Accepted

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


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]

div_list = make_divisors(M)
div_list = div_list[::-1]
for div in div_list:
    if N * div <= M:
        print(div)
        exit()

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,m=nii()

def divisore(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=divisore(m)

for x in d:
  zan=m-(x*n)
  if zan>=0 and zan%x==0:
    print(x)
    exit()

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,m = readInts()
def yaku(m):
    ans = []
    i = 1
    while i*i <= m:
        if m % i == 0:
            j = m // i
            ans.append(i)
            if j != i:
                ans.append(j)
        i += 1
    ans = sorted(ans)
    return ans
ya = yaku(m)
#print(ya)
ans = -1
for a in ya:
    if a * n <= m:
        ans = a
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M = mapint()
from bisect import bisect_left
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]

div = [1]+make_divisors(M)
div.sort()
g = div[bisect_left(div, N)]
print(M//g)

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 1
for d in ds:
    if d*N > M: continue
    ans = max(ans,d)
print(ans)

Submission status: Accepted

Solution code:
import sys
def factors(n):
  a = []
  x = 1
  while x * x <= n :
    if n % x == 0:          
      a.append(x)
      a.append(n//x)
    x += 1
  return a
n,m=map(int,input().split())
fac=factors(m)
fac.sort()
for i in range(len(fac)-1,-1,-1):
  if n*fac[i]<=m:
    print(fac[i])
    sys.exit()

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    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


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
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 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


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

n,m = lr()
f = make_divisors(m)
f.reverse()
for num in f:
    if num * n <= m:
        print(num)
        sys.exit()

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

divisors = make_divisors(M)
ans = 0
for d in divisors:
    if N*d <= M:
        ans = d

print(ans)

Submission status: Accepted

Solution code:
def divisor(n):
  cd = []
  i = 1
  while i*i <= n:
    if n%i==0:
      cd.append(i)
      if i != n//i:
        cd.append(n//i)
    i += 1
  return cd

def solve():
  N, M = map(int, input().split())
  cd = divisor(M)
  cd.sort()
  for c in cd:
    if c<=M//N:
      ans = c
  return ans
print(solve())

Submission status: Accepted

Solution code:
def main():
    import sys

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

    def divisor(m):
        arr = [1, m]
        i = 2
        while i*i <= m:
            if m%i == 0:
                arr.append(i)
                if m//i != i:
                    arr.append(m//i)
            i+= 1
        arr.sort()
        return arr   

    n, m = map(int, input().split())
    a = divisor(m)
    for x in a:
        if x >= n:
            print(m//x)
            return
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

cand = []

for i in range(1, int(sqrt(M))+1):
    if M % i == 0:
        cand.append(i)
        u = M // i
        if u != i:
            cand.append(u)

cand.sort()

ans = 1
for j in cand:
    if N * j <= M:
        ans = max(ans, j)

print(ans)

Submission status: Accepted

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

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]
  
d = make_divisors(M)
d = list(filter(lambda x:x<=M/N,d))

print(d[-1])

Submission status: Accepted

Solution code:
def divisor(n):
  cd = []
  i = 1
  while i*i <= n:
    if n%i==0:
      cd.append(i)
      if i != n//i:
        cd.append(n//i)
    i += 1
  return cd
 
N, M = map(int, input().split())
cd = divisor(M)
cd.sort(reverse=True)
for d in cd:
  if M//d>=N:
    print(d)
    break

Submission status: Accepted

Solution code:
def divisor(n):
    i = 1
    res = set()
    for i in range(1, int(n**.5) + 1):
        if n%i == 0:
            res.add(i)
            res.add(n//i)
    return res

def main():
    n, m = map(int, input().split())
    md = list(divisor(m))
    md.sort(reverse=True)
    for i in md:
        if i*n <= m:
            print(i)
            exit()

if __name__ == '__main__':
    main()