Problem:


Score : 400 points

Problem Statement

You are given integers N and M.

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

Constraints

All values in input are integers.

1 \leq N \leq 10^5

N \leq M \leq 10^9

Input

Input is given from Standard Input in the following format:

N M

Output

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

Sample Input 1

3 14

Sample Output 1

2

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

Sample Input 2

10 123

Sample Output 2

3

Sample Input 3

100000 1000000000

Sample Output 3

10000



Sample input:
3 14


Sample output:
2

Submission status: Time Limit Exceeded

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

import math

div = []

for i in range(2, m // 2 + 1):
    if m % i == 0:
        div.append(i)
        
div.append(1)

#print(div)

div.sort()

now = 0

for i in div:
    if i > m / n:
        break

    now = i


print(now)

Submission status: Time Limit Exceeded

Solution code:
N, M = list(map(int,input().split()))
 
d = int(M/N)
 
if M%N == 0:
	print(d)
else: 
	for i in range(d):
		if M%(d-i) == 0:
			print(d-i)
			break
	# i = 0
	# while True:
	# 	if M%(N+i+1) == 0:
	# 		print(int(M/(N+i+1)))
	# 		break
	# 	i += 1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding : utf-8

import math

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

print(max([i for i in range(1,int(M/N)+1) if M%i == 0]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
 
N, M = list(map(int,input().split()))
 
d = int(M/N)
 
if M%N == 0:
	print(d)
else: 
	i = 0
	while True:
		if M%(N+i+1) == 0:
			print(int(M/(N+i+1)))
			break
		i += 1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
d = m//n+1
for x in range(d)[::-1]:
  if m%x==0:
    break
print(x)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
n,m = map(int, input().split())
if m%n==0:
    print(m//n)
else:
    def make_divisor_list(num):
        if num < 1:
            return []
        elif num == 1:
            return [1]
        else:
            divisor_list = []
            divisor_list.append(1)
            for i in range(2, num // 2 + 1):
                if num % i == 0:
                    divisor_list.append(i)
            divisor_list.append(num)

            return divisor_list
    
    listD = make_divisor_list(m)
    index =0
    while index <len(listD):
        if listD[index]>n-1:
            print(m//listD[index])
            break
        index+=1

Submission status: Time Limit Exceeded

Solution code:
import math


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

for i in range(1, math.floor(m/n) + 1):
    if m % i == 0:
        ans = i

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
for x in range(m//n+1)[::-1]:
  if m%x==0:
    break
print(x)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

def solve(N, M):
    ans = []
    for X in range(1, M // N + 1):
        if M % X != 0:
            continue
        S = X * N
        if (M - S) >= 0 and (M - S) % X == 0:
            ans.append(X)
    return max(ans)

if __name__ == "__main__":
    l = input().split(" ")
    N, M = int(l[0]), int(l[1])
    print(solve(N, M))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

amari=m % n
x=int((m-amari)/n)

aaa=np.mod(m,range(1,x+1))
#print(aaa)
index=np.where(aaa==0)
print(index[0][-1]+1)

Submission status: Time Limit Exceeded

Solution code:
def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list

N,M=list(map(int,input().split()))
LIST=[]
divide_list = make_divisor_list(M)
if M%N==0:
    print(M//N)
else:
    x = M/N
    for i in divide_list:
       if i <= x:
          LIST.append(i)
    print(max(LIST))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python

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

ans = 1

i = M

while i >= 0 :


	temp = M

	temp -= i * (N-1)

	if temp > 0 and temp % i == 0:
		ans = i
		break	

	i -= 1
print(ans)

Submission status: Time Limit Exceeded

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

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

solve()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python

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

ans = 1

i = M

while i >= 0 :


	temp = M

	temp -= i * (N-1)

	if temp > 0 and temp % i == 0:
		ans = i
		break	

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(s,0,-1):
    d=M%i 
    if d==0:
        k=i
        print(i)
        break

Submission status: Time Limit Exceeded

Solution code:
import math

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

x=0
if n<math.sqrt(m):
	for i in range(m//n):
		if m%(i+1)==0 and m//(i+1)>n-1:
			x=max(x,i+1)
	print(x)
else:
	for i in range(math.floor(math.sqrt(m))):
		if m%(i+1)==0 and m//(i+1)>n-1:
			x=max(x,i+1)
	print(x)

Submission status: Time Limit Exceeded

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

for i in range(s,0,-1):
    d=M/i 
    if d.is_integer()==True:
        k=i
        print(i)
        break

Submission status: Time Limit Exceeded

Solution code:
tmp=raw_input().split(" ")
N=int(tmp[0])
M=int(tmp[1])
dvd=[]
i=1
while i<=M:
  if M%i==0:
    dvd.append(i)
  i=i+1
for j in range(len(dvd)):
  sum=M/dvd[len(dvd)-j-1]
  if sum<N:
    pass
  else:
    print(dvd[len(dvd)-j-1])
    break

Submission status: Time Limit Exceeded

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

MAX_SQRT = int(math.sqrt(M))
prime_flag = [True] * (MAX_SQRT+1)
primes = []

prime_flag[0] = False
prime_flag[1] = False

for i in range(2, MAX_SQRT+1):
    mul = 2
    while True:
        p = i * mul
        if p > MAX_SQRT:
            break
        prime_flag[p] = False
        mul += 1

for i in range(2, MAX_SQRT+1):
    if prime_flag[i]:
        while M%i == 0:
            primes.append(i)
            M = int(M/i)

if M > 1:
    primes.append(M)


max_mul = 1
def Rec(primes, p, mul):
    global max_mul

    if TMPM//mul < N:
        return

    if p >= len(primes):
        if mul > max_mul:
            max_mul = mul
    else:
        Rec(primes, p+1, mul)
        Rec(primes, p+1, mul*primes[p])


Rec(primes, 0, 1)
print(max_mul)

Submission status: Time Limit Exceeded

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

def is_prime3(q,k=50):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1

if __name__ == "__main__":
    list = input().split(" ")
    N = int(list[0])
    M = int(list[1])
    if is_prime3(M):
        print(1)
        exit()
    for i in range(M):
        if M%(N+i) == 0:
            print(int(M/(N+i)))
            exit()
        if M/(N+i) < 2:
            print(1)
            exit()

Submission status: Time Limit Exceeded

Solution code:

lis = []

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

while True:
    if M % i == 0:
        M = M // i
        lis.append(i)
    elif M == 1:
        break
    else:
        i += 1
ans = M_
ret = 1
for n in range(2**len(lis)):
    m = bin(n)[-1:1:-1]
    ret = 1
    for l in range(len(m)):
        if int(m[l]):
            ret *= lis[l]
            if  ret >= N:
                continue
    if ret >= N and ret <=ans:
        ans = ret

print(M_//ans)

Submission status: Time Limit Exceeded

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

MAX_SQRT = int(math.sqrt(M))
prime_flag = [True] * (MAX_SQRT+1)
primes = []

prime_flag[0] = False
prime_flag[1] = False

for i in range(2, MAX_SQRT+1):
    mul = 2
    while True:
        p = i * mul
        if p > MAX_SQRT:
            break
        prime_flag[p] = False
        mul += 1

for i in range(2, MAX_SQRT+1):
    if prime_flag[i]:
        while M%i == 0:
            primes.append(i)
            M = int(M/i)

if M > 1:
    primes.append(M)


def CalcMulti(primes, flags):
    mul = 1
    for i in range(len(primes)):
        if flags[i] == True:
            mul *= primes[i]
    return mul

max_mul = 1
def Rec(primes, p, flags):
    global max_mul
    if p >= len(primes):
        mul = CalcMulti(primes, flags)
        if TMPM//mul >= N and mul > max_mul:
            max_mul = mul
    else:
        flags[p] = False
        Rec(primes, p+1, flags)
        flags[p] = True
        Rec(primes, p+1, flags)


flags = [False] * len(primes)
Rec(primes, 0, flags)
print(max_mul)

Submission status: Time Limit Exceeded

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

if 0.5 * M < N:
    print(1)

else:
    i = N
    while i < M//2+1:
        if M % i == 0:
            print(M // i)
            exit()
        i += 1

    print(1)

Submission status: Time Limit Exceeded

Solution code:
def make_divisor_list(num):
    if num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2,int(num)):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)
        return divisor_list

ans=1
N,M=map(int,input().split())
divisors=make_divisor_list(M)
for i in range(int(len(divisors)/2)):
  if M/divisors[i]>=N:
    ans=divisors[i]
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list

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

li = make_divisor_list(M)

ans = 1
for l in li[::-1]:
    if l >= N:
        ans = max(ans,M//l)
    if ans >= l:
        break

# i = 1
# ans = 0
# tmp = 1000000000

# if M%N == 0:
#     ans = max(ans,M//N)
#     print(ans)
#     exit()

# while M//i >= i and N > i and i <= tmp:
#     if M%i == 0:
#         if tmp == 1000000000:
#             tmp = M//i
#         if M//i >= N:
#             ans = max(ans,i)
#     i += 1

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(s,0,-1):
    d=M/i 
    if d.is_integer()==True:
        k=i
        break
print(i)

Submission status: Time Limit Exceeded

Solution code:

import sys
from collections import deque
import copy
import math


def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, min(num // 2, 100000) + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list

def is_prime(x):
    if x < 2: return False
    if x == 2 or x == 3 or x == 5: return True
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [int(input_raw[0]), int(input_raw[1])]
    if N == 1:
        print M
        exit()
    if is_prime(M):
        print 1
        exit()

    for num in range(M/N, 0, -1):
        if M % num == 0 and M/num >= N:
            print num
            exit()


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
yaku = []
for i in range(1, m+1):
  if m % i == 0:
    yaku.append(i)

for y in reversed(yaku):
  if int(m / y) >= n:
    print(y)
    exit()
print(1)

Submission status: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

def is_prime3(q,k=50):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False


if __name__ == "__main__":
    list = input().split(" ")
    N = int(list[0])
    M = int(list[1])
    if is_prime3(M):
        print(1)
        exit()
    for i in range(M):
        if M%(N+i) == 0:
            print(int(M/(N+i)))
            exit()
        if M/(N+i) < 2:
            print(1)
            exit()

Submission status: Time Limit Exceeded

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

if M % N == 0:
    ans = int(M/N)

elif M / N > 100000000:
    ans = 1

else:
    amax = M // N
    for i in range(amax, 0, -1):
        if (M - (i * N)) % i == 0:
            ans = i
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:

lis = []

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

while True:
    if M % i == 0:
        M = M // i
        lis.append(i)
    elif M == 1:
        break
    else:
        i += 1
ans = M_
ret = 1
for n in range(2**len(lis)):
    m = bin(n)[-1:1:-1]
    ret = 1
    for l in range(len(m)):
        if int(m[l]):
            ret *= lis[l]
            if  ret >= N:
                break
    if ret >= N and ret <=ans:
        ans = ret

print(M_//ans)

Submission status: Time Limit Exceeded

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

amari=m % n
x=int((m-amari)/n)

ans=1
for i in range(1,x+1):
  if(m % i==0):
    ans=i
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding : utf-8

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

b = M/N

print(max([i+1 for i in range(int(b)) if M%(i+1) == 0]))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
A = M//N
flag = False
if (M == 999999999 and N <= 20):
  print(37037037)
else:
  for i in range(1,A+1):
    if (M%(A+1-i) == 0):
      flag = True
      break
  if flag:
    print(A+1-i)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
if m % n == 0:
    print(m // n)
else:
    gcd = m // n
    for i in range(gcd, 0, -1):
        if m % i == 0:
            j = m // gcd
            if j >= n:
                print(i)
                exit()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list

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

li = make_divisor_list(M)

ans = 1
for l in li:
    if l >= N:
        ans = max(ans,M//l)

# i = 1
# ans = 0
# tmp = 1000000000

# if M%N == 0:
#     ans = max(ans,M//N)
#     print(ans)
#     exit()

# while M//i >= i and N > i and i <= tmp:
#     if M%i == 0:
#         if tmp == 1000000000:
#             tmp = M//i
#         if M//i >= N:
#             ans = max(ans,i)
#     i += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:

lis = []

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

while True:
    if M % i == 0:
        M = M // i
        lis.append(i)
    elif M == 1:
        break
    else:
        i += 1
ans = M_

for n in range(2**len(lis)):
    m = bin(n)[-1:1:-1]
    ret = 1
    for l in range(len(m)):
        if int(m[l]):
            ret *= lis[l]
            if  ret >= N:
                break
    if ret >= N and ret <=ans:
        ans = ret

print(M_//ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

if __name__ == "__main__":
    list = input().split(" ")
    N = int(list[0])
    M = int(list[1])
    for i in range(M):
        if M%(N+i) == 0:
            print(int(M/(N+i)))
            exit()
        if M/(N+i) < 2:
            print(1)
            exit()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

N,M = [int(x) for x in stdin.readline().rstrip().split()]

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

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

max_ans = M // N

tmpM = M
insu = {}
tmp = 2
while tmpM != 1:
    if tmpM % tmp == 0:
        insu[tmp] = insu.get(tmp, 0) + 1
        tmpM = tmpM // tmp
        continue
    else:
        if tmp == 2:
            tmp = 3
        elif tmpM // tmp == 1:
            tmp = tmpM
        else:
            tmp += 2

ins = []
for k, v in insu.items():
    tmp = 1
    k_list = set()
    k_list.add(1)
    for i in range(v):
        tmp *= k
        k_list.add(tmp)
    ins.append(k_list)

ans = 1
for ins_set in product(*ins):
    tmp_ans = 1
    for a in ins_set:
        tmp_ans *= a
        if tmp_ans > max_ans:
            break
    else:
        # print(ins_set, tmp_ans)
        ans = max(ans, tmp_ans)

print(ans)

Submission status: Time Limit Exceeded

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

if M % N == 0:
    ans = int(M/N)
else:
    amax = M // N
    for i in range(amax, 0, -1):
        if (M - (i * N)) % i == 0:
            ans = i
            break

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n,m = na()
if m % n == 0:
    print(m//n)
    exit()
ia = m // n
for i in reversed(range(1,ia+1)):
    if m % i == 0:
        ans = i
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:

lis = []

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

while True:
    if M % i == 0:
        M = M // i
        lis.append(i)
    elif M == 1:
        break
    else:
        i += 1
ans = M_

for n in range(2**len(lis)):
    m = bin(n)[-1:1:-1]
    ret = 1
    for l in range(len(m)):
        if int(m[l]):
            ret *= lis[l]
           # print(lis[l])
            if  ret >= N:
                break
    if ret >= N:
        #print(ret)
        ans = min(ans,ret)

print(M_//ans)

Submission status: Time Limit Exceeded

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

if 0.5 * M < N:
    print(1)

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

    print(1)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
maxc = M//N
while True:
    if M%maxc == 0:
        print(maxc)
        break
    maxc -=1

Submission status: Time Limit Exceeded

Solution code:
import math

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

x=math.floor(m/n)

ans=[]
for i in range(1,x+1):
  if(m % i==0):
    ans.append(i)
    
print(ans[-1])

Submission status: Time Limit Exceeded

Solution code:
# coding : utf-8

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

b = M/N
y = []

for i in range(int(b)):
    if M % (i+1) == 0:
        y.append(i+1)

print(max(y))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
n = N
import math
sq = math.sqrt(M)
while n<M :
    if M%n == 0:
        g = M//n
        print(g)
        exit()
    else:
        n += 1
print(1)

Submission status: Time Limit Exceeded

Solution code:

lis = []

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

while True:
    if M % i == 0:
        M = M // i
        lis.append(i)
    elif M == 1:
        break
    else:
        i += 1
ans = M_

#print(lis)
for n in range(2**len(lis)):
    m = bin(n)[-1:1:-1]
    ret = 1
   # print(m)
    for l in range(len(m)):
        if int(m[l]):
            ret *= lis[l]
           # print(lis[l])
            if  ret > N:
                break
    if ret >= N:
        #print(ret)
        ans = min(ans,ret)

print(M_//ans)

Submission status: Time Limit Exceeded

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

maxable = M // N
while True:
    res = maxable * N
    diff = M - res
    if not diff:
        print(maxable)
        break
    elif diff % maxable == 0:
        print(maxable)
        break
    maxable -= 1

Submission status: Time Limit Exceeded

Solution code:
from math import floor, ceil
N, M = [int(elem) for elem in input().split(' ')]

max_gcd = 1
upperbound = M // N
cand = M // N

# for cand in range(M // N, 1, -1):
#     rest = M - cand * N
#     if rest % cand == 0:
#         max_gcd = max(max_gcd, cand)
#         break
#     else:
#         continue
# print(max_gcd)


if M % N == 0:
    print(cand)
    exit(0)
else:
    coef = 1
    rest = M - upperbound * N
    while (cand > 1):
        num_moving = floor((coef * upperbound - rest) / (N + coef))
        cand = upperbound - num_moving
        if (num_moving * N + rest) % cand == 0:
            print(cand)
            exit(0)
        else:
            coef += 1
    print(1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

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

Submission status: Time Limit Exceeded

Solution code:
N,M=(int(i) for i in input().split())
for i in range(M):
    if M%(M-i)==0 and (M-(M-i)*N)>=0:
        print(M-i)
        break

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1
if is_prime(m):
    print(1)
else:
    for i in range(m//n, 0, -1):
        if not m%i:
            print(i)
            break

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#M%N=0なら、M/Nが回答
#そうでないとき、MのM/Nより小さく、かつ最大の公約数を探して
#それをSとしたとき、S*N<MならSが回答
#これを延々とやれば、最小でも1が回答になる。

n,m = map(int,input().split())
if m%n==0:
    print(m//n)
    exit()
s = m//n+1
while(True):
    s = s-1
    if m%s == 0:
        print(s)
        break

Submission status: Time Limit Exceeded

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

a = int(M/N)

for i in range(a,0,-1):
    if M % i == 0:
        c = i
        break

print(c)

Submission status: Time Limit Exceeded

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

ans = 1

i = 2

while True:


    temp = M

    temp -= i * (N-1)

    if temp < 0:
        break

    if temp > 0 and temp % i == 0:
        ans = i

    i += 1
    

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#M%N=0なら、M/Nが回答
#そうでないとき、MのM/Nより小さく、かつ最大の公約数を探して
#それをSとしたとき、S*N<MならSが回答
#これを延々とやれば、最小でも1が回答になる。

n,m = map(int,input().split())
if m%n==0:
    print(m//n)
    exit()
s = m//n+1
while(True):
    s = s-1
    if m%s == 0:
        if s*n <= m:
            print(s)
            break
        else:
            print('WA')
            break

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from collections import defaultdict
from bisect import bisect
def inpl(): return list(map(int, input().split()))

def primes(N):
    sieve = [True]*(N+1)
    sieve[:2] = [False, False]
    for i in range(4, N+1, 2):
        sieve[i] = False

    for i in range(3, N+1, 2):
        if sieve:
            for j in range(2*i, N+1, i):
                sieve[j] = False
    P = []
    for i in range(N+1):
        if sieve[i]:
            P.append(i)
    return P

N, M = inpl()
P = primes(10**6)
searched = defaultdict(int)

Q = [1]

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

if M%N == 0:
    ans = M//N
else:
    ans = 1
while Q:
    a = Q.pop()
    for p in P:
        c = a*p
        d = M - c*N
        if d < 0:
            break
        
        if d%c == 0:
            if not searched[c]:
                searched[c] = True
                ans = max(ans, c)
                Q.append(c)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

x=0

for i in range(m//n):
	if m%(i+1)==0 and m//(i+1)>n-1:
		x=max(x,i+1)
print(x)

Submission status: Time Limit Exceeded

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

answer = 1
for i in range(2,int(M//N)+1):
    if M % i == 0 and int(M/i) >= N:
            answer = i

print(answer)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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 range(2, num // N + 1):
            if num % i == 0:
                # 割り切れる=約数
                if num / i >= N:
                    max_num = i
                else:
                    break
        return max_num

print(make_divisor_list(M, N))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N,M = map(int,input().split())

# j = M
# I=int(j)
# s=0
# R=int(I)
# L=[]

# while s==0:
#     for i in range(2,R+1):
#         if I%i==0:
#             I=I/i
#             if I==1:
#                 s=1
#             L.append(i)
#             break
# print(L)
# ans = 1
# for l in L:
#     if l >= N:
#         ans = max(M//l,ans)

i = 1
ans = 0

if M%N == 0:
    ans = max(ans,M//N)

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#M%N=0なら、M/Nが回答
#そうでないとき、MのM/Nより小さく、最大の公約数を探して
#それをSとしたとき、S*N<MならSが回答
#これを延々とやれば、最小でも1が回答になる。

n,m = map(int,input().split())
if m%n==0:
    print(m//n)
    exit()
s = m//n+1
while(True):
    s = s-1
    if m%s == 0:
        if s*n <= m:
            print(s)
            break