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:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())



N,M = inpl()
dl = []
for d in range(1,int(math.sqrt(M))):
    if M%d == 0:
        dl.append(d)
        dl.append(M//d)

dl.sort()
ans = 1
for p in dl:
    if N*p <= M:
        ans = p
    else:
        break

print(ans)

Submission status: Accepted

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

if __name__=='__main__':
  solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ans = 1
for n in range(1, 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:
import math


def read():
    return int(input())


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


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


def usage(n):
    fct = factorize(n)
    ret = []
    for div in divisorize(fct):
        ret.append(num(div))
    return ret

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


N, M = readmap()
if M == 1:
    print(1)
    quit()
div = usage(M)
ans = 0
for d in div:
    if N * d <= M:
        ans = max(ans, d)
print(ans)

Submission status: Accepted

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

i = 1
ans = 1
while i ** 2 <= M:
    if M % i == 0:
        if i * N <= M:
            ans = max(i, ans)
        x = M // i
        if x  * N <= M:
            ans = max(x, ans)
    
    i += 1

print(ans)

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-

def main():
    n, m = map(int, input().split())
    ans = 1
    for i in range(1, int(m**0.5)+1):
        if m % i == 0:
            if m >= i * n:
                ans = max(ans, i)
            if m >= (m // i) * n:
                ans = max(ans, m // i)
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from fractions import math

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

ans = 1
for i in range(1,int(math.sqrt(M))+1):
    if M%i==0: #Mの約数か
        j = M//i
        if j<=M/N and j>ans:
            ans = j
        elif i<=M/N and i>ans:
            ans = i
            
print(ans)

Submission status: Accepted

Solution code:
import math

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

sqrtM = math.floor(math.sqrt(M))
maxd  = min(sqrtM, M // N)

d1 = max(      d for d in range(1, maxd  + 1) if M % d == 0)
d2 = max((M // d for d in range(N, sqrtM + 1) if M % d == 0), default=1)
print(max(d1, d2))

Submission status: Accepted

Solution code:
def make_divisor(n):
    divisor = [1, n]
    i = 2
    while i * i <= n:
        q, r = divmod(n, i)
        if r == 0:
            divisor.append(i)
            divisor.append(q)
        i += 1
    return sorted(divisor)


n, m = [int(v) for v in input().split()]
divisors = make_divisor(m)

ans = 1
maxv = m // n
for v in divisors:
    if v <= maxv:
        ans = v
    else:
        break

print(ans)

Submission status: Accepted

Solution code:
def make_divisor(n):
    divisor = set([1, n])
    i = 2
    while i * i <= n:
        q, r = divmod(n, i)
        if r == 0:
            divisor.add(i)
            divisor.add(q)
        i += 1
    return sorted(list(divisor))


n, m = [int(v) for v in input().split()]
divisors = make_divisor(m)

ans = 1
maxv = m // n
for v in divisors:
    if v <= maxv:
        ans = v
    else:
        break

print(ans)

Submission status: Accepted

Solution code:
import math

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

def divisors(M):
    for d in range(1, math.floor(math.sqrt(M)) + 1):
        if M % d == 0:
            yield d
            yield M // d

d = max(d for d in divisors(M) if d <= M // N)
print(d)

Submission status: Accepted

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

if N == 1:
    print(M)
else:
    d = max(d for d in range(1, M // N + 1) if M % d == 0)
    print(d)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
from math import sqrt
ANS = []
N,M = map(int,input().split())
L = np.arange(1,int(sqrt(M))+1,dtype=int)
#L = sorted(L,reverse = True)
for i in L :
    if M % i == 0 :
        ANS.append(i)
        ANS.append(M//i)
ANS = sorted(ANS,reverse = True)
for j in ANS :
    if j * N <= M :
        print(j)
        break

Submission status: Accepted

Solution code:
import math
 
N, M=input().split(" ")
N=int(N)
M=int(M)
 
def get_number(M):
    result=list()
    for i in range(1,int(math.sqrt(M))):
        if M%i==0:
            result.append(i)
            result.append(int(M/i))
    result.sort()
    return(result)
    
def check_number(N,M):
    if N==1:
        return(M)
    number=get_number(M)
    answer=list()
    for i in number:
        if M/i>=N:
            answer.append(i)
            
    return(answer[-1])
    
print(check_number(N,M))

Submission status: Accepted

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

ans = 1
for a in range(1, int(math.sqrt(M))):
    b = int(M / a)
    if M%a != 0:
        continue
    if a * N <= M:
        ans = max(ans, a)
    if b * N <= M:
        ans = max(ans, b)

print(ans)

Submission status: Accepted

Solution code:
def f():
  n,m=map(int,input().split())
  for i in range(m//n+1)[::-1]:
    if m%i==0:return i
print(f())

Submission status: Accepted

Solution code:
# encoding: utf-8
import math
N, M = map(int, input().split())

rM = int(math.sqrt(M))

pairs = []
for a in range(1, rM + 1):
    if M % a == 0: pairs.append((a, M // a))

# a_i = p * b_i
# b_1 + b_2 + ... = m
p_max = 0
for m, p in filter(lambda x: x[0] >= N, pairs):
    if p > p_max: p_max = p

for p, m in filter(lambda x: x[1] >= N, pairs):
    if p > p_max: p_max = p

print(p_max)

Submission status: Accepted

Solution code:
import math

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

if N == 1:
    print(M)
else:
    d = max(d for d in range(1, math.ceil(M / (N - 1))) if M % d == 0)
    print(d)

Submission status: Accepted

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

# 速度調整版
def primes(n):
    sq = int(math.sqrt(n)+1)
    ss = 30030
    a = [None] * (ss)
    a[0] = 1
    t = 1
    for i in range(2,ss):
        if not a[i] is None:
            continue
        if t * i > ss:
            break
        t *= i
        for j in range(i*2,ss,i):
            a[j] = 1
    a = [i for i in range(t) if a[i] is None]
    d = collections.defaultdict(int)
    for i in a[1:]:
        while n % i == 0:
            n //= i
            d[i] += 1

    for j in range(1,sq//t+2):
        if j > n:
            break
        for ii in a:
            i = t*j+ii
            while n % i == 0:
                n //= i
                d[i] += 1
    if n > 1:
        d[n] += 1

    return d

# 約数をすべて返す
def divisions(n):
    d = primes(n)

    r = [1]
    for k, v in d.items():
        for c in r[:]:
            for i in range(1,v+1):
                r.append(c*(k**i))

    return sorted(r)


def main():
    n,m = LI()
    d = divisions(m)
    # print(len(d),d)
    r = 1
    for c in d:
        if c * n > m:
            break
        r = c

    return r


print(main())

Submission status: Accepted

Solution code:
import sys
import math
N,M=map(int,input().split())
ans=0
a=min(M+1,10**5)
b=M//N
for i in range(1,a):
    if M%i!=0:
        continue
    if i<=b:
        ans=max(ans,i)
    if M//i <=b:
        ans=max(ans,M//i)
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
if M == 1:
  print(1)
  exit(0)
  
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
  
fct = factorize(M)
#print(fct, num(fct))

ans = 1
for div in divisorize(fct):
    #print(div, num(div))
    temp = num(div)
    if N * temp <= M:
      ans = max(ans, temp)
      
print(ans)

Submission status: Accepted

Solution code:
def main():
    """
    input:
        1 <= N <= 10^5
        N <= M <= 10^9

        a1 + a2 + ... + aN = M
        1 <= ai

    output:
        数列の項の最大公約数の最大値
    """
    N, M = map(int, input().split())

    # ans = f(N, M)
    ans = editorial(N, M)
    print(ans)


def f(N, M):
    """
    最大公約数1:
        1が含まれる
        互いに素

    最大公約数2:
        すべて2の倍数

    N=M: すべて1
    M=奇数: 最大公約数は奇数
    まず1ずつ配る
        M -= N

    N,M: 0は偶数、1は奇数
    0 0: 配ってもMは偶数のまま
    0 1: 配ってもMは奇数のまま
         1余るので配る時に２回分配る、余りはどれかに割り当てて偶数にする
    1 0: 奇数回目の配るときには奇数、偶数回目のときは偶数
    1 1: 配ってもMは奇数のまま、01と同じパターン

    """
    if N == 1:
        return M

    if N == M or M < N * 2:
        return 1

    # 1回は確実に配れる
    ans = 1
    d = 1
    M -= M
    while M >= N:
        # 配る
        M -= N
        d += 1

        # 残りをいい感じに分配したときに、今まで配った回数の最大公約数を維持できるか?
        if True:
            ans = d

    return ans


def editorial(N, M):
    """
    すべての項がK倍なら、最大公約数は最低でもKであり、それらの和であるMもKの倍数
    Mの約数は、M=A*B=B*A の対称性より
        最大 root(10^9) まで試せば良いのでTLEしない
    N=1,M=10^9のとき、最初の考えではTLEになる
    """
    ans = 1
    a_max = int(M ** 0.5)
    for a in range(1, a_max + 1):
        if M % a != 0:
            continue

        # aで割り切れるので、もう片方も試す
        b = M // a

        # e.g. N=5, M=120, a=15, M = (N + x) * a,  xは正負ゼロどれか
        # 15 + 15 + 15 + 15 + 15 = 15 * 5 = 75, rest=45 = 15 * 3
        # a * N はaの倍数、Mもaの倍数、より残りもaの倍数なのでどれかの項に配ればよい
        if a * N <= M:
            ans = max(ans, a)
        if b * N <= M:
            ans = max(ans, b)

    return ans


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    from math import sqrt

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

    # See:
    # https://www.youtube.com/watch?v=CURWJ1Dr44A
    for k in range(1, int(sqrt(m)) + 1):
        if m % k != 0:
            continue

        if k * n <= m:
            ans = max(ans, k)

        b = m // k

        if b * n <= m:
            ans = max(ans, b)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import sqrt
n, m = list(map(int, input().split()))
i = 1
lst = []
while i <= sqrt(m):
    if m % i == 0:
        j = m // i
        if i >= n:
            lst.append(i)
        if j >= n:
            lst.append(j)
    i += 1
print(m//min(lst))

Submission status: Accepted

Solution code:

# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


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


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


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


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def fs(n):
    f = Counter()
    for i in range(2, math.ceil(math.sqrt(n)) + 1):
        if i > n:
            break
        while n % i == 0:
            f[i] += 1
            n /= i
    if int(n) != 1:
        f[int(n)] = 1
    return f

@mt
def slv(N, M):
    ans = 1
    for m in range(1, math.ceil(math.sqrt(M))+1):
        if M % m != 0:
            continue
        
        if  N*m <= M:
            ans = max(ans, m)
        if  N*(M//m) <= M:
            ans = max(ans, M//m)

    return ans


def main():
    N, M = read_int_n()
    print(slv(N, M))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def f(M):
    l = []
    for i in range(1,int(math.sqrt(M))+1):
        if M%i==0:
            l.append(i)
    n = len(l)
    for i in range(n):
        j = l[n-1-i]
        if M/j!=j:
            l.append(M//j)
    return l

l = f(M)

for i in range(len(l)):
    n = l[-1-i]
    if M/n >= N:
        ans = n
        break
print(ans)

Submission status: Accepted

Solution code:
import math, operator
from collections import Counter
from itertools import chain, product, permutations, combinations
from functools import reduce, lru_cache
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]
    # Prime Factor Decomposition
    @classmethod
    def pfd(cls, n):
        rn = math.ceil(math.sqrt(n))
        primes = cls.primes_sieve(rn)

        factors = []
        cur = n
        for p in primes:
            while True:
                div, rem = divmod(cur, p)
                if rem == 0:
                    factors.append(p)
                    cur = div
                else:
                    break
        if cur != 1 or not factors:
            factors.append(cur)
        return factors
    # List up aliquots
    @classmethod
    def aliquots(cls, n):
        pf = cls.pfd(n)
        pfc = Counter(pf)
        ppv = [[pow(p, i) for i in range(n+1)] for p,n in pfc.items()]
        return map(lambda x: reduce(operator.imul, x), product(*ppv))

N, M = map(int, input().split())
max_ans = M // N
print(max(filter(lambda a: a <= max_ans, PrimeUtils.aliquots(M))))

Submission status: Accepted

Solution code:
import itertools
import math
import copy

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

M2=copy.deepcopy(M)

A={}

a=int( math.sqrt(M) )+2

for i in range(2,a):
	while M%i==0:
		if i not in A:
			A[i]=1
		else:
			A[i]+=1
		M/=i
else:
	A[M]=1



B=[]

for x in A.values():
	B.append( range(x+1) )


L=list(itertools.product(*B))


Y=[]	#Yakusu
for x in L:
	t=1
	for i,j in zip(A,x):
		t*=i**j
	Y.append(t)


ans=0
for cd in Y:	#cd: Common Divivor(yakusu)
	if M2/cd>=N:
		ans=max(ans,cd)

print ans

Submission status: Accepted

Solution code:
import math, operator
from collections import Counter
from itertools import chain, product, permutations, combinations
from functools import reduce, lru_cache
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]
    @classmethod
    # Prime Factor Decomposition
    def pfd(cls, n):
        rn = math.ceil(math.sqrt(n))
        primes = cls.primes_sieve(rn)

        factors = []
        cur = n
        for p in primes:
            while True:
                div, rem = divmod(cur, p)
                if rem == 0:
                    factors.append(p)
                    cur = div
                else:
                    break
        if cur != 1 or not factors:
            factors.append(cur)
        return factors
    @classmethod
    # List up aliquots
    def aliquots(cls, n):
        pf = cls.pfd(n)
        pfc = Counter(pf)
        ppv = [[pow(p, i) for i in range(n+1)] for p,n in pfc.items()]
        return map(lambda x: reduce(operator.imul, x), product(*ppv))

N, M = map(int, input().split())
print(M // min(filter(lambda a: N <= a, PrimeUtils.aliquots(M))))

Submission status: Accepted

Solution code:
import math, operator
from collections import Counter
from itertools import chain, product, permutations, combinations
from functools import reduce, lru_cache
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]
    @classmethod
    # Prime Factor Decomposition
    def pfd(cls, n):
        rn = math.ceil(math.sqrt(n))
        primes = cls.primes_sieve(rn)

        factors = []
        cur = n
        for p in primes:
            while True:
                div, rem = divmod(cur, p)
                if rem == 0:
                    factors.append(p)
                    cur = div
                else:
                    break
        if cur != 1 or not factors:
            factors.append(cur)
        return factors
    @classmethod
    # List up aliquots
    def aliquots(cls, n):
        pf = cls.pfd(n)
        pfc = Counter(pf)
        ppv = [[pow(p, i) for i in range(n+1)] for p,n in pfc.items()]
        return map(lambda x: reduce(operator.imul, x), product(*ppv))

N, M = map(int, input().split())
for factor in sorted(PrimeUtils.aliquots(M)):
    if N <= factor:
        print(M // factor)
        break
else:
    print(1)

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:
		l.append(i)
		l.append(m // i)

ans = 1
for d in l:
	if d * n <= m:
		ans = max(ans, d)

print(ans)

Submission status: Accepted

Solution code:
#これでどうだ
def 解():
    iN,iM = [int(_) for _ in input().split()]
    iD = iM // iN
    if iM % iN == 0:
        print(iD)
    elif 2*iN > iM :
        print(1)
    else:
        aD = []
        iRtM = int(iM**0.5)
        if iRtM > iD:
            for i in range(iD,0,-1):
                if iM % i == 0:
                    print(i)
                    exit()
        else:
            aRet = []
            for i in range(1,iRtM+1):
                if iM % i ==0:
                    if iRtM / 2 > i:
                        aRet.append(i)
                        if iD > iM // i :
                            print (iM // i)
                            exit()
                    else:
                        print (i)
                        exit()
            print(max(aRet))
解()

Submission status: Accepted

Solution code:
#こういう場合分けは通るのか？
iN,iM = [int(_) for _ in input().split()]
iD = iM // iN
if iM % iN == 0:
    print(iD)
elif 2*iN > iM :
    print(1)
else:
    aD = []
    iRtM = int(iM**0.5)
    if iRtM > iD:
        for i in range(iD,0,-1):
            if iM % i == 0:
                print(i)
                exit()
    else:
        aRet = []
        for i in range(1,iRtM+1):
            if iM % i ==0:
                if iRtM / 2 > i:
                    aRet.append(i)
                    if iD > iM // i :
                        print (iM // i)
                        exit()
                else:
                    print (i)
                    exit()
        print(max(aRet))

Submission status: Accepted

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

max_ans = M // N

ans = 1

for n in range(1, int(M ** 0.5) + 1):
    if M % n != 0:
        continue

    if n <= max_ans:
        ans = max(ans, n)
    if M // n <= max_ans:
        ans = max(ans, M // n)

print(ans)

Submission status: Accepted

Solution code:
import math

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


sr = int(math.sqrt(M))

result = 1

for i in range(sr, 0, -1):
    if M % i == 0:
        r = i
        if M >= N * r:
            result = max(r, result)
        r = M // i
        if i >= N:
            result = max(r, result)

print(result)

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
maxlim = int(m**0.5)+1
minj = m
for j in range(1,maxlim+1):
    rem = m%j
    if rem == 0:
        div = m//j
        if j >= n and j < minj:
            minj = j
        elif div >= n and div < minj:
            minj = div

k = m//minj
print(k)

Submission status: Accepted

Solution code:
def 解():
    iN,iM = [int(_) for _ in input().split()]
    iD = iM // iN
    if iM % iN == 0:
        print(iD)
    elif 2*iN > iM :
        print(1)
    else:
        aD = []
        for i in range(1,int(iM**0.5)+1):
            if iM % i == 0:
                if iD > i : aD.append(i)
                j = iM // i
                if iD > j :aD.append(j)
        print(max(aD))
解()

Submission status: Accepted

Solution code:
iN,iM = [int(_) for _ in input().split()]
iD = iM // iN
if iM % iN == 0:
    print(iD)
elif 2*iN > iM :
    print(1)
else:
    aD = []
    for i in range(1,int(iM**0.5)+1):
        if iM % i == 0:
            if iD > i : aD.append(i)
            j = iM // i
            if iD > j :aD.append(j)
    print(max(aD))

Submission status: Accepted

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


def get_line():
    return input()


def get_tokens():
    return get_line().split()


def get_ints():
    return [int(_) for _ in get_tokens()]


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

    divs = []

    div = 1
    while div * div <= m:
        if m % div == 0:
            divs.append(div)
            if div * div < m:
                divs.append(m // div)
        div += 1
        
    divs.sort()
    ratios = [m // div for div in divs]

    i = 0
    while i + 1 < len(divs) and ratios[i + 1] >= n:
        i += 1
    print(divs[i])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

i = 1
ans = 0
while True:
    if i * i > M + 1:
        break
    j = M // i
    if M % i == 0 and M // i >= N:
        ans = max(ans, i)
    if M % j == 0 and M // j >= N:
        ans = max(ans, j)
    i += 1
    

print(ans)

Submission status: Accepted

Solution code:
import math
import time
n, m = map(int, input().split())
flag=0
if m%n==0:
    print(m//n)

else:
    start = time.time()
    index=m//n
    while index >0:
        elapsedTime = time.time()-start
        if elapsedTime > 1:
            flag=1
            break
        elif m%index==0:
            print(index)
            break
        index-=1

    if flag==1:
        index = 1
        while index < m+1:
            if m % index == 0:
                if index > n-1:
                    print(m//index)
                    break
            index += 1

Submission status: Accepted

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

def canMake(div):
    return (M//div) - (N-1) >= 1 

ans = 1
for i in range(1, M):
    if i * i > M:
        break
    if M % i != 0:
        continue
    a, b = i, M//i
    if canMake(a):
        ans = max(ans, a)
    if canMake(b):
        ans = max(ans, b)
print(ans)

Submission status: Accepted

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

def canMake(div):
    #return (M%div == 0) and (M//div) - (N-1) >= 1 
    return N * div <= M

ans = 1
for i in range(1, M):
    if i * i > M:
        break
    if M % i != 0:
        continue
    a, b = i, M//i
    if canMake(a):
        ans = max(ans, a)
    if canMake(b):
        ans = max(ans, b)
print(ans)

Submission status: Accepted

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

m = M
f = {}
while m%2 == 0:
    f[2] = f.get(2,0) + 1
    m = m//2

k = 3
l = int(m**0.5)+1
while m != 1:
    if k > l:
        f[m] = f.get(m,0)+1
        break
    while m%k == 0:
        f[k] = f.get(k,0)+1
        m = m//k
    k += 2
C=[1]
for k in f:
    C_tmp = []
    for c in C:
        for i in range(f[k]):
            C_tmp.append(c*(k**(i+1)))
    C.extend(C_tmp)
ans_r = M
for c in C:
    if c>=N and c<ans_r:
        ans_r = c
print(M//ans_r)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def get_list_divisor(N, reverse=True):
    try:
        F = get_prime_factorized(N)
        L = re_func_divisior(F)
        R = []
        for l in L:
            for i, x in enumerate(l):
                if i == 0:
                    r = x
                else:
                    r *= x
            R.append(r)
        R.sort()
        if reverse == True:
            R.reverse()
    except:
        if N == 1:
            R = [1]
        else:
            R = [N]
    return R

def re_func_divisior(F):
    b, e = F.pop()
    P = re_func_divisior(F) if F else [[]]
    Q = [[b ** k] for k in range(e + 1)]
    return [p + q for p in P for q in Q]


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

for d in get_list_divisor(M, reverse=True):
    if d * N <= M and M % d == 0:
        print(d)
        break

Submission status: Accepted

Solution code:
from itertools import product

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

max_ans = M // N

ans = 1
tmp = 2
tmpM = M
max_prime = int(M ** 0.5)
all_list = []
i = -1
k = 0
div = 2
while tmpM != 1:
    if tmpM % div == 0:
        tmpM = tmpM // div
        if k == 0:
            i += 1
            all_list.append(set())
            all_list[i].add(div ** k)
            k += 1
        all_list[i].add(div ** k)
        k += 1

    else:
        k = 0
        if div == 2:
            div = 3
        elif div > max_prime:
            div = tmpM
        else:
            div += 2

if all_list == []:
    print(1)
    exit()

# print(all_list)
ans = 1

for div_tuple in product(*all_list):
    tmp = 1
    for k in div_tuple:
        tmp *= k
        if tmp > max_ans:
            break
    else:
        ans = max(ans, tmp)

print(ans)

Submission status: Accepted

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