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: Wrong Answer

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(n=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(n+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, n+1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## const ##
MOD=10**9+7
## libs ##
import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
    n, m = MII()
    c = {}
    for i in range(1,int(m**0.5)+1):
        if m%i == 0:
            p = m//i
            if p >= n:
                c[i] = p
    print(max(c.keys()))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m = na()

if n == 1:
    print(m)
    exit()

i = 1
ans = 1
while i * i <= m:
    if m % i == 0:
        if m // i >= n:
            ans = i
    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m = na()

i = 1
ans = 1
while i * i <= m:
    if m % i == 0:
        if m // i >= n:
            ans = i
    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

prime_list = primes(1000)
p_list = set(prime_list)

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

ans = 1

for i in prime_list:
    if n * i > m:
        break
    if m % i == 0:
        num = m // i
        if num in p_list:
            ans = i
        elif num < n:
            continue
        elif num >= i * n:
            a = num // n
            ans = i * a
    else:
        continue

print(ans)

Submission status: Wrong Answer

Solution code:
print("hello")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M=map(int, input().split())
#均等に配分したい
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

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

Submission status: Wrong Answer

Solution code:
import math
N, M = map(int,input().split())
b = 0
P = [1]
for k in range(2,math.floor(math.sqrt(M))+1):
    if M % k == 0:
        P.append(k)
        P.append(M//k)
P = sorted(P)
for e in P:
    if e >= N:
        print(M//e)
        exit(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
if m%n == 0: print(m//n)
else:
  if m%2 == 0: print(2)
  else: print(3)

Submission status: Wrong Answer

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

t = fractions.gcd(m//n,m%n)
print(t)

Submission status: Wrong Answer

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,m=map(int,input().split())
    for x in range(m//n+1,0,-1):
        if (m-n*x)%x==0:
            print(x)
            break

if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

n, m = map(int, input().split())
if n == 1:
    ans = m
else:
    ans = 1
    i = 1
    limit = m ** 0.5
    while i <= limit:
        if m % i == 0 and m // i >= n:
            ans = max(ans, i)
        i += 1
print(ans)

Submission status: Wrong Answer

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

n, m = map(int, input().split())
ans = 1
i = 1
limit = m ** 0.5
while i <= limit:
    if m % i == 0 and m // i >= n:
        ans = max(ans, i)
    i += 1
print(ans)

Submission status: Wrong Answer

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

n, m = map(int, input().split())
ans = 1
i = 1
while i <= n:
    if m % i == 0 and m // i >= n:
        ans = max(ans, i)
    i += 1
print(ans)

Submission status: Wrong Answer

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

n, m = map(int, input().split())
ans = 1
i = 1
while i <= m ** 0.5:
    if m % i == 0 and m // i >= n:
        ans = max(ans, i)
    i += 1
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

P = min(N, M/N)
ans = 0
i = 2
while(i <= P):
  if(M % i == 0):
    ans = i
  i += 1
  
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
x=m//n
y=m%n
from fractions import gcd
print(gcd(x,y))

Submission status: Wrong Answer

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

N,M=map(int,input().split())
divisors=make_divisors(M)
ans=0
for d in divisors:
    if N*d<=M:
        ans=d
    else:
        break

Submission status: Wrong Answer

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

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

def main():
    x = M // N
    a_N = M - (N - 1) * x
    a_i = x
    print(gcd(a_i, a_N))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

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

    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import bisect

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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


def resolve():
    n, m = map(int, input().split())

    if m % n == 0:
        print(m // n)
    else:
        ma = m // n
        div = make_divisors(m)
        idx = bisect.bisect_left(div, ma)
        print(div[idx - 1])


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

if m % n == 0:
  print(m//n)
else:
  print(m%n)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import itertools
def factorization(n):
    arr = []
    temp = n
    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


N,M= list(map(int, stdin.readline().strip().split()))
so=factorization(M)
cnt=0
youso=len(so)
indexx=youso-1
for i in range(youso):
    cnt+=so[i][1]
for i in range(cnt):
    num=1
    for j in range(youso):
        num*=so[j][0]**(so[j][1])
    if M/N>=num:
        print(num)
        exit()

    if so[indexx][1]!=0:
        so[indexx][1]-=1
    if indexx==0:
        indexx=youso-1
    else:indexx-=1

Submission status: Wrong Answer

Solution code:
from sys import stdin
import itertools
def factorization(n):
    arr = []
    temp = n
    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


N,M= list(map(int, stdin.readline().strip().split()))
so=factorization(M)
cnt=0
youso=len(so)
indexx=youso-1
for i in range(youso):
    cnt+=so[i][1]
for i in range(cnt-1,-1,-1):
    num=1
    for j in range(youso):
        num*=so[j][0]**(so[j][1])
    if N*num<=M:
        print(num)
        exit()

    if so[indexx][1]!=0:
        so[indexx][1]-=1
    if indexx==0:
        indexx=youso-1
    else:indexx-=1

Submission status: Wrong Answer

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

from fractions import gcd

def make_divisors(n: int):
    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

divisors = make_divisors(M)

ans = 0
for i in range(1, len(divisors)):
    d = divisors[i]
    ans = max(ans, gcd(d, M-(d*(N-1))))

print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
from fractions import gcd
print(gcd(M//N, M-((M//N)*(N-1))))

Submission status: Wrong Answer

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

if n == 1:
    print(m)
    exit(0)
for i in range(int(m**0.5), 0, -1):
    if m % i == 0:
        if i * n - m <= 0:
            print(i)
            exit(0)

Submission status: Wrong Answer

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

for i in range(int(m**0.5), 0, -1):
    if m % i == 0:
        if i * n - m <= 0:
            print(i)
            exit(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(int(-(-m**0.5//1))+1,1,-1):
    if m % i == 0:
        if i*n -m <=0:
            print(i)
            exit(0)
print(1)

Submission status: Wrong Answer

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

for i in range(int(-(-m**0.5//1)),1,-1):
    if m % i == 0:
        if i*n -m <=0:
            print(i)
            exit(0)
print(1)

Submission status: Wrong Answer

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

P=math.ceil(M**0.5)
ans=1
i=1

while i<=P:  #iは小さい側とする
  if M%i==0:
    if M//i>=N:
      ans=max(ans,i)
  i +=1
      
print(ans)

Submission status: Wrong Answer

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

P=math.ceil(M**0.5)
ans=1
i=1

while i<=P:
  if M%i==0:
    j = M//i
    if j>=N:
      ans=j
  i +=1
      
print(ans)

Submission status: Wrong Answer

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

P=math.ceil(M**0.5)
ans=1
i=1

while i<=P:
  if M%i==0:
    j = M//i
    if j>=N:
      ans=i
  i +=1
      
print(ans)

Submission status: Wrong Answer

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

P=math.ceil(M**(1/2))
ans=1

for i in range(1,P+1):
  if M%i==0:
    j = M//i
    if j>=N:
      ans=i
      
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections
from math import ceil
ma = lambda : map(int,input().split())
ni = lambda : int(input())

n,m = ma()
gcd = 1
for d in range(max(1,m//n-n),m//n+n):
    q,r = divmod(m,d)
    if r == 0 and q>=n:gcd = d
print(gcd)

Submission status: Wrong Answer

Solution code:
# (o) recursionはダメ
# (o) 素因数はO(sqrt(N))で求められる
# (x) 具体的な計算

"""
Memo:
- A=[a1,...,an]の最大公約数をDとする
- sum(A)=MもDで割り切れる，よってDはMの約数 (Mも割れる)

2条件
- DがMの約数であって，M >= N * Dであるとき
    - a1=...=an-1=D, an = M - (N - 1) * D は全てDで割り切れる (最大公約数)
- Mの約数かつM // N以下の整数で最大
"""

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

# 約数を求める
factors = []
i = 2
while i * i <= M + 1:
    if M % i == 0:
        factors.append(i)
        if M // i != i:
            factors.append(M // i)
    i += 1

factors.sort(reverse=True)
# Mの約数でM // N以下の最大
for f in factors:
    if M // f >= N:
        print(f)
        exit()

Submission status: Wrong Answer

Solution code:
# (o) recursionはダメ
# (o) 素因数はO(sqrt(N))で求められる
# (x) 具体的な計算

"""
Memo:
- A=[a1,...,an]の最大公約数をDとする
- sum(A)=MもDで割り切れる，よってDはMの約数 (Mも割れる)

2条件
- DがMの約数であって，M >= N * Dであるとき
    - a1=...=an-1=D, an = M - (N - 1) * D は全てDで割り切れる (最大公約数)
- Mの約数かつM // N以下の整数で最大
"""

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

# 約数を求める
factors = []
i = 2
while i * i <= M + 1:
    if M % i == 0:
        factors.append(i)
        if M // i != i:
            factors.append(M // i)
    i += 1

# print(M)
# print(factors)

# Mの約数でM // N以下の最大
ans = 1
for factor in factors:
    if factor <= M // N:
        ans = factor
print(ans)

Submission status: Wrong Answer

Solution code:
# (o) recursionはダメ
# (o) 素因数はO(sqrt(N))で求められる
# (x) 具体的な計算

"""
Memo:
- A=[a1,...,an]の最大公約数をDとする
- sum(A)=MもDで割り切れる，よってDはMの約数 (Mも割れる)

2条件
- DがMの約数であって，M >= N * Dであるとき
    - a1=...=an-1=D, an = M - (N - 1) * D は全てDで割り切れる (最大公約数)
- Mの約数かつM // N以下の整数で最大
"""

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

# 約数を求める
factors = []
i = 2
while i * i <= M + 1:
    if M % i == 0:
        factors.append(i)
    i += 1

# print(M)
# print(factors)

# Mの約数でM // N以下の最大
ans = 0
for factor in factors:
    if factor <= M // N:
        ans = factor
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

# Return a list of the prime factors for a natural number bigger than 1
def trial_division(n):
    if n < 2:
        return []

    prime_factors = []

    for i in range(2, int(n**0.5)+1):
        # nがi（の累乗）で割り切れるかを調べる
        while n % i == 0:
            # nがiで割り切れる場合、iを素因数としてリストに追加する
            prime_factors.append(i)
            # nをiで割った商で更新しておく
            n //= i
    # nの平方根より大きい素因数が存在する場合
    if n > 1:
        prime_factors.append(n)

    return prime_factors

def factorization(n):
    arr = []
    temp = n
    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
  
def get_divisors(n):
    # nの素因数のリストを得る
    prime_factors = trial_division(n)
    divisors = set()

    for i in range(1, len(prime_factors)+1):
        # 素因数をi個選んだ時の組み合わせ
        combinations = list(itertools.combinations(prime_factors, i))

        # 素因数を掛け合わせて約数を得る
        for comb in combinations:
            divisor = 1
            for num in comb:
                divisor *= num
            divisors.add(divisor)

    # 1を約数として加える
    divisors.add(1)
    return divisors
  
N,M=map(int,input().split())

q=sorted(get_divisors(M),reverse=True)
q=q[1:]

for num in q:
  if M//num >= N:
    print(num)
    break

Submission status: Wrong Answer

Solution code:
import itertools

# Return a list of the prime factors for a natural number bigger than 1
def trial_division(n):
    if n < 2:
        return []

    prime_factors = []

    for i in range(2, int(n**0.5)+1):
        # nがi（の累乗）で割り切れるかを調べる
        while n % i == 0:
            # nがiで割り切れる場合、iを素因数としてリストに追加する
            prime_factors.append(i)
            # nをiで割った商で更新しておく
            n //= i
    # nの平方根より大きい素因数が存在する場合
    if n > 1:
        prime_factors.append(n)

    return prime_factors

def factorization(n):
    arr = []
    temp = n
    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
  
def get_divisors(n):
    # nの素因数のリストを得る
    prime_factors = trial_division(n)
    divisors = set()

    for i in range(1, len(prime_factors)+1):
        # 素因数をi個選んだ時の組み合わせ
        combinations = list(itertools.combinations(prime_factors, i))

        # 素因数を掛け合わせて約数を得る
        for comb in combinations:
            divisor = 1
            for num in comb:
                divisor *= num
            divisors.add(divisor)

    # 1を約数として加える
    divisors.add(1)
    return divisors
  
N,M=map(int,input().split())

q=sorted(get_divisors(M),reverse=True)
q=q[1:-1]

for num in q:
  if M//num >= N:
    print(num)
    break

Submission status: Wrong Answer

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

  def prime_factorize(n):
    # nの素因数分解
    a = []
    while n % 2 == 0:
      a.append(2)
      n = n // 2
    f = 3
    while f * f <= n:
      if n % f == 0:
        a.append(f)
        n = n // f
      else:
        f += 2
    if n != 1:
      a.append(n)
    return a

  if m % n == 0:
    ans = m // n
    print(ans)
    return

  pf = sorted(prime_factorize(m))
  ans = 1
  d = 1
  for p in pf:
    d *= p
    # m//d がn以上なら、dをn個に分配できる？ 最適の証明？
    if m // d >= n: ans = d
    else: break
  print(ans)

abc112_d()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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
div = make_divisors(n)
for i in div[::-1]:
    if i <= m / n:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
cnt = n
while n > 1:
    if m % n == 0 and n*cnt <= m:
        break
    else:
        n -= 1
print(n)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
while n > 1:
    if m % n == 0:
        break
    else:
        n -= 1
print(n)

Submission status: Wrong Answer

Solution code:
import sys


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


sys.setrecursionlimit(10 ** 9)


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

    def make_divisors(n):
        divisors = []
        cnt = 0
        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)
                    cnt += 1

        divisors.sort()
        return cnt, divisors

    cnt, divisor = make_divisors(M)
    for i in range(cnt):
        if M // divisor[cnt - i] >= N:
            print(divisor[cnt - i])
            return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
ans = 1
for i in range(2, 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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  ans=1
  if n==1:
    return m
  for i in range(1,int(math.sqrt(m)+1)):
    if m%i==0:
      if i*n>m:
        continue
      ans=max(ans,i)
      x=m//i
      if x*n<m:
        ans=max(ans,x)

  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  ans=1
  if n==1:
    return m
  for i in range(1,int(math.sqrt(m)+1)):
    if m%i==0:
      if i*n>m:
        continue
      ans=i

  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  ans=1
  if n==1:
    return m
  for i in range(1,int(math.sqrt(m)+1)):
    if m%i==0:
      if i*n>m:
        continue
      x=m-(i*n)
      if x%i==0:
        ans=i

  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  ans=1
  if n==1:
    return m
  for i in range(1,int(math.sqrt(m)+1)):
    if m%i==0:
      if i*n>m:
        continue
      x=m-i*n
      if x%i==0:
        ans=max(ans,i+x//n)

  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  ans=1
  if n==1:
    return m
  for i in range(1,int(math.sqrt(m)+1)):
    if m%i==0:
      if i*n>m:
        continue
      x=m-i*n
      if x%i==0:
        ans=max(ans,i+x//i)

  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  ans=1
  if n==1:
    return m
  for i in range(1,int(math.sqrt(m)+1)):
    if m%i==0:
      if i*n>m:
        continue
      x=m-i*n
      if x%i==0:
        ans=i

  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  ans=1
  for i in range(1,int(math.sqrt(m)+1)):
    if m%i==0:
      if i*n>m:
        continue
      x=m-i*n
      if x%i==0:
        ans=i

  return ans

# main()
print(main())

Submission status: Wrong Answer

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


def divisor(x, reverse=False):
    if reverse:
        r = range(int(x**.5), 0, -1)
    else:
        r = range(1, int(x**.5)+1)
    for i in r:
        if x % i == 0:
            yield i


factor = divisor(m, reverse=True)
for f in factor:
    if m // n >= f:
        ans = f
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections

sys.setrecursionlimit(10**6)
N, M = map(int, input().split())

def factor(m):
    fac = collections.Counter()
    while (m&1) == 0:
        m >>= 1
        fac[2] += 1
    for p in range(3, m, 2):
        if p*p > m:
            break
        if m % p == 0:
            m //= p
            fac[p] += 1
    if m > 1:
        fac[m] += 1
    return fac

fac = factor(M)

def search(i, ps, divisor):
    if M < N * divisor:
        return 1
    if i == len(ps):
        assert M % divisor == 0
        return divisor
    p, cnt = ps[i]
    dmax = 1
    for j in range(cnt+1):
        dmax = max(dmax, search(i+1, ps, divisor))
        divisor *= p
    return dmax

print(search(0, list(fac.items()), 1))