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())
ans = 1
if N == 1:
    print(M)
    exit()

for i in range(2, int(M ** .5) + 1):
    p, q = divmod(M, i)
    if q == 0:
        if p >= N:
            ans = max(ans, i)
        if i >= N:
            ans = max(ans, p)

print(ans)

Submission status: Accepted

Solution code:
import math

N,M=map(int,input().split())
MR=math.ceil(math.sqrt(M))

LISTM=[]
for i in range(1,MR+1):
    if M%i==0:
        LISTM.append(i)
        LISTM.append(M//i)
    
LISTM.sort()
LISTM.reverse()

for j in LISTM:
    if j<=M//N:
        print(j)
        break

Submission status: Accepted

Solution code:
import  math
lis = []

N,M = [int(i) for i in input().split()]

for i in range(1,int(math.sqrt(M))):
    if M % i == 0:
        lis.append(i)
        lis.append(M//i)


lis.sort()
i =1
for i in lis:
    if i >= N:
        break

print(M//i )

Submission status: Accepted

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


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

    return sorted(divisors)


divisors = get_divisor(M)
for d in divisors:
    if d >= N:
        print(M // d)
        exit()

print(1)

Submission status: Accepted

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

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

solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
iN,iM = [int(_) for _ in input().split()]

if iM % iN == 0:
    print(iM // iN)
else:
    aRet = []
    for i in range(1,iM//iN + 1):
        if iM % i == 0:
            aRet.append(i)
    print(aRet[-1])

Submission status: Accepted

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

def make_divisor_list(num, N):

    if num < 1:
        return 0
    elif num == 1:
        return 1
    else:
        max_num = 1
        for i in reversed(range(2, num // N + 1)):
            if num % i == 0:
                # 割り切れる=約数
                if num / i >= N:
                    max_num = i
                    break
                #else:
                #    break
        return max_num

print(make_divisor_list(M, N))

Submission status: Accepted

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

ans=0
for i in range(1,int(m**0.5)+2):
    if m%i==0 :
        a=m//i
        if min(a,i)>=n :
            ans=max(ans,max(a,i))
        elif max(a,i)>=n :
            ans=max(ans,min(a,i))
print(ans)

Submission status: Accepted

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

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


for i in pfac(m):
    if m % i == 0 and m / i >= n:
        values.append(i)
print(max(values))

Submission status: Accepted

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

s = M // N
r_list = []
for i in range(1, int(math.sqrt(M)) + 1):
    if M % i == 0 and i <= s:
        if M // i <= s:
            r_list.append(M // i)
        else:
            r_list.append(i)
r_list.sort()
r_list.reverse()
print(r_list[0])

Submission status: Accepted

Solution code:
import math

n, m = [int(i) for i in input().split()]
ret = []

i = 1
while i * i <= m:
    if m % i == 0:
        ret.append(i)
        ret.append(int(m / i))
    i += 1
#ret.append(m)
ret = sorted(ret)
#print(ret)
for i in reversed(ret):
    if i <= int(m/n):
        print(i)
        exit()

Submission status: Accepted

Solution code:
import math, sys, random

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

def is_prime(n):
    if n == 2: return True
    if n == 1 or n & 1 == 0: return False

    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    for k in range(100):
        a = random.randint(1, n - 1)
        t = d
        y = pow(a, t, n)

        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1

        if y != n - 1 and t & 1 == 0:
            return False

    return True

d = int(math.floor(M/N))

if M%N == 0:
	print(d)
	sys.exit()

i = 0
f = False
while True:
	if M%(N+i+1) == 0:
		print(int(M/(N+i+1)))
		sys.exit()
	i += 1
	if i == 100000 and is_prime(M):
		print(1)
		sys.exit()

Submission status: Accepted

Solution code:
from itertools import product
from collections import Counter
from functools import reduce
import operator
num_product = lambda it: reduce(operator.mul,it,1)

# 素因数分解
def prime_factors(n):
  i = 2
  while i * i <= n:
    if n % i:
      i += 1
    else:
      n //= i
      yield i
  if n > 1:
    yield n



N,M = map(int,input().split())
P = tuple(tuple(p**i for i in range(d+1)) for p,d in Counter(prime_factors(M)).items())
def it():
  for nums in product(*P):
    t = num_product(nums)
    yield t
print(max(t for t in it() if t*N <= M))

Submission status: Accepted

Solution code:
import math
a = list(map(int,input().split()))

b = a[1]//a[0]

c = []

for i in range(1,int(math.sqrt(a[1]))+1):
    if a[1] % i == 0 and i <= b:
        if a[1] // i <= b:
            c.append(a[1] // i)
        else:
            c.append(i)
c.sort()
c.reverse()
print(c[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import sqrt
n, m = [int(x) for x in input().split()]

def getDiviser(x):
  result = []
  for i in range(1, int(sqrt(x))+2):
    if x % i == 0:
      result.append(i)
      result.append(x//i)
  result.sort()
  result.reverse()
  return result

for x in getDiviser(m):
  if m//x >= n:
    print(x)
    break
else:
  print(0)

Submission status: Accepted

Solution code:
def factorize(n):
    fct = []  
    b, e = 2, 0  
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop() 
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]

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

if M == 1:
    print(1)
else:
    re = 1
    fa = factorize(M)
    div_list = divisorize(fa)

    for i in range(len(div_list)):
        num = 1
        for j in range(len(div_list[-1 - i])):
            l = div_list[-1-i][j]
            num *= l[0] ** l[1]
        d = M // num 
        if d >= N and num > re:
            re = num
    print(re)

Submission status: Accepted

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

Submission status: Accepted

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

factors = set()
for i in range(1, math.ceil(rootM)+1):
  if M % i == 0:
    factors.add(i)
    factors.add(M // i)
factarr = sorted(list(factors))
print(M // factarr[bisect.bisect_left(factarr, N)])

Submission status: Accepted

Solution code:
import math
def get_div_list(num):
    if num == 1:
        return [1]
    else:
        div_list = []
        div_list.append(1)
        div_list.append(num)
        for i in range(2, math.floor(math.sqrt(num))+ 1):
            if num % i == 0:
                div_list.append(i)
                div_list.append(num // i)
        list(set(div_list))
        div_list.sort(reverse = True)
        return div_list

n, m = [int(i) for i in input().split()]
d_list = get_div_list(m)

for i in d_list:
    if (n-1)*i < m:
        if (m - (n-1)*i) % i == 0:
            print(i)
            break

Submission status: Accepted

Solution code:
from math import sqrt

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

l=[]

for i in range(1,int(sqrt(m))+1):
    if m%i==0:
        if i>=n:
            l.append(int(m/i))
        if m/i>=n:
            l.append(i)

print(max(l))

Submission status: Accepted

Solution code:
from math import floor, sqrt

# xの約数を求める
def getDivisor(x):
    ans = []
    for d in range(1, floor(sqrt(x)) + 1): # 1からスタート
        if x % d == 0:
            ans.append(d)
            if x // d != d:
                ans.append(x // d)

    return sorted(ans)


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

divs = getDivisor(M)
for div in reversed(divs):
    if M // div >= N:
        print(div)
        break

Submission status: Accepted

Solution code:



def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a


x,n = map(int,input().split())
if x == 1 and n == 1:
    print(1)
    exit()
fct = factorize(n)


divlist=[]
for div in divisorize(fct):
    divlist.append(num(div))

divlist.sort()
ans = 1
for i in range(0,len(divlist)):
    if divlist[i] <= n/x:
        ans = divlist[i]
print(ans)

Submission status: Accepted

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

import math
class PrimeUtils:
    @staticmethod
    def primes_sieve(n):
        sieve = [True] * (n + 1)
        for i in range(2, n + 1):
            if sieve[i]:
                for j in range(i + i, n + 1, i):
                    sieve[j] = False
        return [i for i, x in enumerate(sieve[2:], 2) if x]

def f():
    for p in PrimeUtils.primes_sieve(math.ceil(math.sqrt(M))):
        if M % p == 0:
            for x in range(N, (M//2) + 1):
                if M % x == 0:
                    return M // x
            else:
                return 1
    return 1
print(f())

Submission status: Accepted

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

S = M / N
S = int(S)
#print(S)
import math
if N == 1:
    ans = M
else:
    not_sosu = -1
    for i in range(2, int(math.sqrt(M)) + 1):
        if M % i == 0:
            not_sosu = 1
            if M / i >= N and M % i == 0:
                ans = max(ans, i)
            j = M // i
            if M / j >= N and M % j == 0:
                ans = max(ans, j)
            #print(i)
    if not_sosu == -1:
        ans = 1


if N == 1:
    ans = M

print(ans)

Submission status: Accepted

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

m = M//N

# def prime_factors(n):
#     i = 2
#     factors = OrderedDict()
#     while i * i <= n:
#         if n % i:
#             i += 1
#         else:
#             n //= i
#             if i in factors:
#               factors[i] += 1
#             else:
#               factors[i] = 1
#     if n > 1:
#       if n in factors:
#         factors[n] += 1
#       else:
#         factors[n] = 1
#     return factors

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

if M == 1:
  print(1)
  exit()

fct = factorize(M)
current_n = 1

for div in divisorize(fct):
    n = num(div)
    if n <= m and current_n < n:
      current_n = n

print(current_n)

# for x in range(m, 0, -1):
#   if M % x == 0:
#     print(x)
#     break

Submission status: Accepted

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

    print(b)

Submission status: Accepted

Solution code:
import math
n, m = map(int, input().split())
ans = 1
k = m
soy = []
for i in range(2, int(math.sqrt(m))+1):
    if k % i == 0:
        are = 0
        while True:
            if k % i == 0:
                k = k // i
                are += 1
            else:
                break
        soy.append([i, are])
if k != 1:
    soy.append([k, 1])
for i in range(10-len(soy)):
    soy.append([1, 0])
for a in range(soy[0][1] + 1):
    for b in range(soy[1][1] + 1):
        for c in range(soy[2][1] + 1):
            for d in range(soy[3][1] + 1):
                for e in range(soy[4][1] + 1):
                    for f in range(soy[5][1] + 1):
                        for g in range(soy[6][1] + 1):
                            for h in range(soy[7][1] + 1):
                                for i in range(soy[8][1] + 1):
                                    for j in range(soy[9][1] + 1):
                                        t = soy[0][0]**a * soy[1][0]**b * soy[2][0]**c * soy[3][0]**d * soy[4][0]**e * soy[5][0]**f * soy[6][0]**g * soy[7][0]**h * soy[8][0]**i * soy[9][0]**j
                                        if n <= t:
                                        	ans = max(ans, m//t)
print(ans)

Submission status: Accepted

Solution code:
import bisect
n,m = map(int,input().split())
a = m//n

anslist = []
for i in range(1,int(m**0.5)+2):
    if m%i==0:
        anslist.append(i)
ansl = anslist.copy()
ansl.reverse()
for i in ansl:
    anslist.append(m//i)
    
anslist = list(set(anslist))
anslist.sort()
pos = bisect.bisect_left(anslist,n)
print(m//anslist[pos])

Submission status: Accepted

Solution code:
# coding:utf-8


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


N, M = inpl()

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

Submission status: Accepted

Solution code:
import math

def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b
M, N = getMN()

yakusuu = []
for i in range(1,int(math.sqrt(N))+2):
    if N % i == 0:
        yakusuu.append(i)
        yakusuu.append(N//i)

yakusuu = (sorted(yakusuu))
for y in yakusuu[::-1]:
    #print(y)
    if y * M <= N:
        print(y)
        break

Submission status: Accepted

Solution code:
#coding:utf-8
import numpy as np
def divisor(n,m):
    arr = []
    for i in range(1,(int(np.sqrt(m))+1)):
        if m % i == 0:
            if i <= m/n:
                arr.append(i)
            if m/i <= m/n:
                arr.append(int(m/i))
    return arr



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

Submission status: Accepted

Solution code:
import math

N, M = map(int, input().split(" "))
div1 = []
div2 = []

for i in range(1, int(math.sqrt(M))+1):
    if M % i == 0:
        div1 += (i,)
        div2 += (M//i,)
for d in div2:
    if d * N <= M:
        print(d)
        break
else:
    div1 = div1[::-1]
    for d in div1:
        if d * N <= M:
            print(d)
            break

Submission status: Accepted

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

Submission status: Accepted

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

if N >= 1000:
    for i in range(M//N):
        n = (M//N)-i
        if M % n == 0:
            print(n)
            break
else:
    x = M//(M//N)
    for i in range(M):
        i = x +i
        if M % i == 0:
            print(M//i)
            break

Submission status: Accepted

Solution code:
def primeFactor(N):
    i = 2
    ret = {}
    n = N
    if n < 0:
        ret[-1] = 1
        n = -n
    if n == 0:
        ret[0] = 1
    while i**2 <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
            ret[i] = k
        i += 1
    if n > 1:
        ret[n] = 1
    return ret

def isPrime(N):
    if N <= 1:
        return False
    return sum(primeFactor(N).values()) == 1

def findPrime(N):
    if N < 0:
        return -1
    i = N
    while True:
        if isPrime(i):
            return i
        i += 1

def divisor(N):
    pf = primeFactor(N)
    ret = [1]
    for p in pf:
        ret_prev = ret
        ret = []
        for i in range(pf[p]+1):
            for r in ret_prev:
                ret.append(r * (p ** i))
    return sorted(ret)
    
N, M = map(int, input().split(" "))

for i in divisor(M):
    if i >= N:
        print (M//i)
        break

Submission status: Accepted

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

ds = [i for i in range(1, int(m ** 0.5) + 1) if m % i == 0]
ds.extend([m // i for i in ds])
print(max([i for i in ds if i <= m // n]))

Submission status: Accepted

Solution code:
import math
n,m = map(int,input().split())	
r = m
k = 0
a = [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, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]
for i in range(len(a)):
    if m%a[i] == 0 and m >= a[i]:
        r = m//a[i]
        break
if r == m and m >= 199:
    r = m//199
if n > r:
    k = 1

while n <= r :
    if m % n == 0:
        break
    n += 1
if n == r + 1 or k == 1:
    print(1)
else:
    print(m//n)

Submission status: Accepted

Solution code:
#112D
N,M=map(int,input().split())
B=int((M**(1/2))//1)
A=[M//i for i in range(1,int((M**(1/2)+1)//1))]+list(range(1,B))
A.sort(reverse=True)
for i in A:
    flag=M-N*i
    if flag%i==0 and flag>=0:
        print(i)
        break

Submission status: Accepted

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

else:
    for i in reversed(range(1, ulim+1)):
        if M%i == 0:
            print(i)
            break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=[int(x) for x in input().split()]
import sys
if n==1:
    print(m)
    sys.exit()
ans=1
index=2
while True:
    tmp=index
    if tmp*n>m:
        break
    if m%tmp==0:
        ans=index
    index+=1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]

def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a
def yaku(n):
    fct = factorize(n)
    y = divisorize(fct)
    ys = []
    for yy in y:
        ys.append(num(yy))
    ys.sort()
    return ys

n,m = list(map(int,input().split()))
if n == 1 and m == 1:
    print(1)
else:
    y = yaku(m)
    print(np.max(np.array(y)[np.array(y) <= m/n]))

Submission status: Accepted

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

ans = 0
for i in range(int(m ** 0.5)):
      if m % (i+1) == 0 and m // (i+1) >= n:
          if m // (i+1) >= n:
              ans = max(ans, i+1)
          if i+1 >= n:
              ans = max(ans, m // (i+1))
print(ans)

Submission status: Accepted

Solution code:
def factorize(M):
    fact=[]
    for i in range(2,10**5):
        tmp=[1]
        if M==1:
            break
        while M%i==0:
            M//=i
            tmp.append(tmp[-1]*i)
        if len(tmp)>1:
            fact.append(tmp)
    if M!=1:
        fact.append([1,M])
    return fact

def divisor(fact,arr,i,p):
    if i == len(fact):
        arr.append(p)
        return 0
    for x in fact[i]:
        divisor(fact,arr,i+1,p*x)
    
N,M=list(map(int,input().split()))

fact = factorize(M)
arr=[]
divisor(fact,arr,0,1)
arr=sorted(arr)
ans=1
for x in arr:
    if x>M//N:
        break
    ans=x
print(ans)

Submission status: Accepted

Solution code:
import math

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

ys = []

for i in range(1, int(math.sqrt(m)) + 2):
    if m % i == 0:
        ys.append(i)

ys2 = ys.copy()

for y in reversed(ys):
    ys2.append(m // y)

for y in reversed(ys2):
    if y <= m // n:
        print(y)
        break

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
nums = []
target = m

for i in range(1,pow(10,9)+1):
  if m <= i*i:
    break
  if target % i == 0:
    nums.append([i,target//i])
  if target == 1:
    break

keep = 0
for x in range(len(nums)):
  if n <= nums[x][0]:
    print(nums[x][1])
    exit()
  elif n <= nums[x][1]:
    keep = nums[x][0]
if 0 < keep:
  print(keep)
else:
  print(1)

Submission status: Accepted

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

devs = []
for i in range(1,int((m+1) ** (1/2))+1):
    if m % i == 0:
        devs.append(i)
        devs.append(m // i)

devs = sorted(list(set(devs)), reverse=True)

for dev in devs:
    if m // dev >= n:
        print(dev)
        break

Submission status: Accepted

Solution code:
import itertools


def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct
def factorize_list(n):
    result = []
    for val,perm in factorize(n):
        result+= [val]*perm
    return result



def mul(args):
    r =1
    for v in args:
        r*= v
    return r

def getcomb(l):
    if len(l)==0:
        return [1]
    result = []
    v,perm = l[0]
    for i in range(perm+1):
        result+= [(v**i)*val for val in getcomb(l[1:])]
    return result


N,M=list(map(int,input().split()))
factorized = factorize(M)
result=1
for i in range(len(factorized)//2+1):
    for vals in getcomb(factorized):
        A= vals
        B= M//A
        #print(A,B,vals)
        if A>=N:
            result = max(B,result)
        if B>=N:
            result = max(A,result)


print(result)

Submission status: Accepted

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

div = []
l = int(sqrt(M))+1
ans = (1)
for j in range(1,l):
    if M % j == 0:
        if j * N <= M:
            ans = max(ans,j)
        if (M//j) * N <= M:
            ans = max(ans,(M//j))


print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ans = 1
for i in range(N, min(M+1, 100000)):
    q, m = divmod(M, i)
    if m==0:
        ans = q
        break
else:
    for i in range(100000, 0, -1):
        q, m = divmod(M, i)
        if q < N: continue
        if m==0:
            ans = i
            break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    M = int(buflist[1])
    max = 1
    for i in get_divisor_list(M):
        # Mがiで割り切れる、かつ割ったときの値がN以上なら可能なはず
        if M % i == 0 and M / i >= N:
            max = i
    print(max)

# 約数のリストを取得
def get_divisor_list(num):
    div_list = [1, num]
    limit = int(math.sqrt(num))
    for i in range(2, limit+1):
        if num % i == 0:
            div_list.append(i)
            div_list.append(int(num / i))
    return sorted(div_list)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

N, M = list(map(int, input().split()))
x = M // N
Mx = []
m = math.floor(math.sqrt(M))
for i in range(1, m + 1):
	if M % i == 0:
		Mx.append(i)

y = len(Mx)

My = []
for i in range(y):
	My.append(int(M // Mx[- 1 - i]))



for i in range(y):
	Mx.append(My[i])

ans = 1
for i in Mx:
	if i <= x:
		ans = i
	else:
		break

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from math import sqrt, ceil

s_in = lambda: stdin.readline()[:-1] # s = s_in()
d_in = lambda: int(stdin.readline()) # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split())) # List = ds_in()

N, M = ds_in()

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

cand = factorize(M)
for c in cand[::-1]:
    if M//c >= N:
        print(c)
        exit()

Submission status: Accepted

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

    c, div = 1, []
    while c * c <= m:
        if not m % c:
            div.append(c)
            if m // c != c:
                div.append(m//c)
        c += 1

    div.sort(reverse=True)
    for g in div:
        if n <= m // g:
            print(g)
            exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
x=1
if n==1:
    x=m
else:
    for i in range(1,100000000):
        if m%i==0 and i*n<=m:
            x=i
print(x)

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
RC112 D
"""

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

from collections import deque
from math import sqrt
def divisors(x):
    divs = deque()
    sq = int(sqrt(x))
    if sq**2 == x:
        divs.append(sq)
        sq=sq-1
    for i in range (sq,0,-1):
        if x%i==0:
            divs.appendleft(i)
            divs.append(x//i)
    return(divs)


cand = [i for i in divisors(m) if n*i<= m]
print(max(cand))

Submission status: Accepted

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

maxDivisor = 1
for i in range(1, 100001):
    if m % i == 0:
        if i >= n:
            print(m // i)
            exit()
        else:
            if (m // i) >= n: 
                maxDivisor = i
else:
    print(maxDivisor)

Submission status: Accepted

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

i = n
while i*i <= m:
    if m%i == 0:
        print(m//i)
        exit()
    i += 1
j = m//i
while j > 0:
    if m%j == 0:
        print(j)
        exit()
    j -= 1

Submission status: Accepted

Solution code:
iipt=lambda:int(input())
miipt=lambda:map(int,input().split(" "))
from math import sqrt
n,m=miipt()
r=0
for g in range(1, int(sqrt(m)+1)):
    if m%g==0 and m//g>=n:
        r=max(r, g)
    if m%g==0 and g>=n:
        r=max(r, m//g)
print(r)

Submission status: Accepted

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

if M%N==0:
  print(M//N)
else:
  ans= (M//N)
  cnt=[]
  for i in range(1,M):
    if i*i > M:
      break
    if M%i==0:
      cnt.append(i)
      cnt.append(M//i)
      
  cnt.sort(reverse=True)
  for j in range(len(cnt)):
    if cnt[j] < ans:
      ans=cnt[j]
      break
  
  print(ans)

Submission status: Accepted

Solution code:
import math
N,M=list(map(int, input().strip().split()))
i=1
ylist1=[]
ylist2=[]
for i in range(1,int(math.sqrt(M))+1):
    if M%i==0:
        ylist1.append(i)
        ylist2.append(M//i)
ylist=ylist2+ylist1[::-1]
nm=M//N
for i in ylist:
    if i<=nm:
        break
print(i)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
from math import sqrt
from fractions import gcd

n, m = [int(i) for i in input().split()]

def factorize(n):    
    i = 2
    A = defaultdict(int)
    
    while n % i == 0:
        n //= i
        A[i] += 1
    i += 1

    while n != 1 and i <= sqrt(n):
        while n % i == 0:
            n //= i
            A[i] += 1
        i += 2
    if n != 1:
        A[n] = 1

    return A

D = set()
F = list(factorize(m).items())
l = len(F)

memo = dict()

def dfs(i, j, k):
    if (i, j, k) in memo:
        return None
    memo[i, j, k] = True
    if i == l:
        D.add(k)
        return None

    if F[i][1] > j:
        dfs(i, j+1, k*F[i][0])
    dfs(i+1, 0, k)
    
    return None

dfs(0, 0, 1)

D = sorted(list(D), reverse=True)
ans = 1

for d in D:
    if m // n < d:
        continue

    ans = max(ans, gcd(d, m-(d*(n-1))))

print(ans)

Submission status: Accepted

Solution code:
import math

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

factors = []

for i in range(1,int(math.sqrt(M))+10):
	if M % i == 0:
		factors.append(i)
		factors.append(M//i)

ans = 1
for i in factors:
	if N <= M // i:
		ans = max(i,ans)
print(ans)