Problem:


Score : 400 points

Problem Statement

You are given integers N and M.

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

Constraints

All values in input are integers.

1 \leq N \leq 10^5

N \leq M \leq 10^9

Input

Input is given from Standard Input in the following format:

N M

Output

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

Sample Input 1

3 14

Sample Output 1

2

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

Sample Input 2

10 123

Sample Output 2

3

Sample Input 3

100000 1000000000

Sample Output 3

10000



Sample input:
3 14


Sample output:
2

Submission status: Accepted

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

def primefactorize(n):
    fct = []  # return [[p1, power1], [p2, power2], ...]
    p, power = 2, 0
    while p * p <= n:
        while n % p == 0:
            n = n // p
            power += 1
        if power > 0:
            fct.append([p, power])
        if p == 2:
            p += 1
        else:
            p += 2
        power = 0
    if n > 1:
        fct.append([n, 1])
    return fct

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

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

if M != 1:
    fct = primefactorize(M)
    factors = []
    for div in divisorize(fct):
        factors.append(num(div))
else:
    factors = [1]
factors.sort()
k = M//N
L = [x for x in factors if x <= k]
print(max(L))

Submission status: Accepted

Solution code:
ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]


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(1, 100):
            if num % i == 0:
                divisor_list.append(i)
                divisor_list.append(num//i)
        for i in range(2, num // 100 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return sorted(divisor_list)


n,m = ai()
d = make_divisor_list(m)
d = d[::-1]
for k in d:
    if m/k == m//k and m//k >= n:
        print(k)
        exit()
print(1)

Submission status: Accepted

Solution code:
import math
n,m = map(int,input().split())
MAX = m//n
ans = 1
def factorization(n):
    def factor_sub(n, m):
        c = 0
        while n % m == 0:
            c += 1
            n /= m
        return c, n
    #
    buff = []
    c, m = factor_sub(n, 2)
    if c > 0: buff.append((2, c))
    c, m = factor_sub(m, 3)
    if c > 0: buff.append((3, c))
    x = 5
    while m >= x * x:
        c, m = factor_sub(m, x)
        if c > 0: buff.append((x, c))
        if x % 6 == 5:
            x += 2
        else:
            x += 4
    if m > 1: buff.append((m, 1))
    return buff
def divisor_sub(p, q):
    a = []
    for i in range(0, q + 1):
        a.append(p ** i)
    return a

def divisor(n):
    if n == 1:
      return([1])
    xs = factorization(n)
    ys = divisor_sub(xs[0][0], xs[0][1])
    for p, q in xs[1:]:
        ys = [x * y for x in divisor_sub(p, q) for y in ys]
    return sorted(ys)
a = divisor(m)
for i in a:
  if i <= MAX:
    ans = i
print(int(ans))

Submission status: Accepted

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

def solv(N, M):
    d = M//N
    for i in range(d+1)[::-1]:
        if M%i == 0:
            return i

print(solv(N, M))

Submission status: Accepted

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

cands = []
for i in range(1, int(m**(1/2))+1):
    if m%i == 0:
        cands.append(i)
        cands.append(m//i)
cands = sorted(cands, reverse = True)
# print(cands)

for c in cands:
    if m//c >= n:
        print(c)
        break

Submission status: Accepted

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


for i in range(1,int(m**0.5)+1) :

   if m%i==0 :
      c.append(i)
      c.append(m//i)

c.sort()
c.reverse()

for j in range(len(c)) :

   if c[j] <= m//n :
      print(c[j])
      break

Submission status: Accepted

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

i_m = m
import math
root_m = int(math.sqrt(m))

m_s = []
for i in range(2,root_m+1):
    while m%i == 0:
        m_s.append(i)
        m = int(m/i)
        if m == 1:
            break
    if m ==1:
        break

if m_s == []:
    if n == 1:
        print(i_m)
    else:
        print(1)

else:
    for i in range(0,i_m-n+1):
        if i_m%(n+i) == 0:
            print(int(i_m/(n+i)))
            break

Submission status: Accepted

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

res = 1

# brute force
for i in range(1, min(10**5, M+1)):
    if M % i == 0:
        if i >= N:
            res = max(res, M // i)
        if M // i >= N:
            res = max(res, i)
print(res)

Submission status: Accepted

Solution code:
import math
N, M = list(map(int,input().split()))
arr = []
arr_inv = []
M_new = int(math.sqrt(M))+1
for i in range(1,M_new):
    if M % i == 0:
        if i == M // i:
            arr.append(i)
        else:
            arr.append(i)
            arr_inv.append(M // i)
arr_inv.reverse()
arr = arr + arr_inv
for i in range(len(arr)):
    if arr[i] >= N:
        print(M // arr[i])
        break

Submission status: Accepted

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

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

print(g)

Submission status: Accepted

Solution code:
import math

def div(x):
	d=[]
	for i in range(int(math.sqrt(x))):
		if x%(i+1)==0:
			d=d+[i+1]
			d=d+[x//(i+1)]
	return d

N,M=map(int,input().split())
d=div(M)
dmax=-1
for i in range(len(d)):
	if d[i]<=M//N:
		if d[i]>dmax:
			dmax=d[i]
print(dmax)

Submission status: Accepted

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

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

ans = 0
for d in divisors:
    a = M//d
    if a >= N:
        ans = max(ans,d)
print(ans)

Submission status: Accepted

Solution code:
# Thanks for http://nihaoshijie.hatenadiary.jp/entry/2018/02/03/115759

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


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

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

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


try:
    fct = factorize(M)
    L   = []
    for div in divisorize(fct):
        L.append(num(div))
except:
    L = [1, M]

L.sort()
L.reverse()

for l in L:
    if l * N <= M and M % l == 0:
        print(l)
        break

Submission status: Accepted

Solution code:
def run():
	N, M = (int(x) for x in input().split())
	i = 2
	result = 1

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



if __name__ == '__main__':
	run()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
def divisor(n): #約数
    f=[]
    d=[1]
    c=0
    r=int(n**0.5)
    for i in range(2,r+2):
        while n%i==0:
            c+=1
            n=n//i
        if c!=0:
            f.append([i,c])
            c=0
    if n!=1:
        f.append([n,1])
    for i in range(len(f)):
        t=[]
        for j in range(1,f[i][1]+1):
            t.append(f[i][0]**j)
        for j in range(len(d)):
            for k in range(len(t)):
                d.append(d[j]*t[k])
    return sorted(d)
x=divisor(m)
if len(x)==1:
    print(1)
elif n==1:
    print(m)
else: 
    for i in range(len(x)):
        if m/x[i]<n:
            print(x[i-1])
            break

Submission status: Accepted

Solution code:
import math

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

q = m // n

ret = 0
for i in range(1, int(math.sqrt(m))+1):
    if m % i == 0:
        if i <= q and ret < i:
            ret = i
        p = m//i
        if m//i <= q and ret < p:
            ret = p
print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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


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


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

ans_list = []
m,n = map(int, input().split())
if m == 1 and n == 1:
    print(1)
else:
    fct = factorize(n)
    for div in divisorize(fct):
        ans_list.append(num(div))
    ans_list.sort()
    for number in ans_list:
        if number <= (n//m):
            ans = number
    print(ans)

Submission status: Accepted

Solution code:
import sys
import math
N,M = map(int, input().split())
if N==1:
  print(M)
  sys.exit()
tmax = int(M/N)
t = tmax
divisor_list = [1]
for i in range(2, int(math.sqrt(M)) + 1):
  if M % i == 0:
    divisor_list.append(i)
    divisor_list.append(M//i)
divisor_list.sort(reverse = True)
for nums in divisor_list:
  if nums <= tmax:
    print(nums)
    sys.exit()

Submission status: Accepted

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

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

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

ans = 1

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

Submission status: Accepted

Solution code:
from math import sqrt
from bisect import bisect
n,m = (int(i) for i in input().split())
x = []
for i in range(1,int(sqrt(m))+1):
	if m%i==0:
		x.append(i)
		x.append(m//i)
x.sort()
print(x[bisect(x,m//n)-1])

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()

# mの約数を求める
i = 1
div = []
while i*i <= m:
    if m%i == 0:
        div.append(i)
        div.append(m//i)
    i += 1
    
ans = 1
for d in div:
    if m//d >= n:
        ans = max(ans, d)
        
print(ans)

Submission status: Accepted

Solution code:
import math
lis = []
n,m = map(int,input().split())
for i in range(1,math.ceil(math.sqrt(m))+1):
  if m % i == 0:
    lis.append(i)
    lis.append(m//i)
lis.sort()
cou = 0
ans = 0
for i in range(len(lis)):
  if m % lis[i] == 0 and m // lis[i] >= n:
    ans = max(ans,lis[i])
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

# coding: utf-8
# Your code here!

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

yaku1=[]

for i in range(1,10**5):
    if m%i==0:
        yaku1.append(i)

yaku2=[]
for i in yaku1:
    if m//i not in yaku1:
        yaku2.append(m//i)

yaku=yaku1+yaku2

#print(yaku)
print(max([i for i in yaku if m//i >= n]))

Submission status: Accepted

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

target = m / n

while True:
    if (m - target * n) % target == 0:
        print target
        exit(0)
    target -= 1

Submission status: Accepted

Solution code:
from sys import stdin
n,m = map(int,stdin.readline().split())
ans = 1
x = 1
a = []
while x * x <=m:
 if m%x==0:
  a.append(x)
  a.append(m/x)
 x+=1
for i in a:
 if m/i >= n:
  ans = max(ans,i)
print ans

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()

ds = []
for i in range(1, m+1):
    if i*i > m: break
    if m % i == 0:
        ds.append(i)
        if i*i < m:
            ds.append(m//i)
ds.sort()

for d in ds[::-1]:
    if m//d >= n:
        print(d)
        break

Submission status: Accepted

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

k = m
f = set()
for i in range(1, int(m ** 0.5) + 2):
    d, e = divmod(m, i)
    if e == 0:
        f.add(i)
        f.add(m // i)
ppp = sorted(f)
for p in ppp:
    if p >= n:
        print(m // p)
        break
else:
    print(1)

Submission status: Accepted

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

import bisect


def divisors(n):
    ds = []
    for i in range(1, int(n ** 0.5) + 1):
        d, m = divmod(n, i)
        if m == 0:
            ds.append(i)
            ds.append(d)
    ds.sort()
    return ds


def find_ge(a, x):
    i = bisect.bisect_left(a, x)
    if i != len(a):
        return a[i]
    raise ValueError


def solve(n, m):
    ds = divisors(m)
    t = find_ge(ds, n)
    return m // t


def main():
    n, m = (int(z) for z in input().split())
    res = solve(n, m)
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = map(int, raw_input().strip().split())
div = []
for i in xrange(1, int(m ** 0.5) + 1):
    if i * i == m: div.append(i)
    elif m % i == 0:
        div.append(i)
        div.append(m // i)
div.sort()

ans = 1
for d in div:
    if m // d < n:
        break
    else:
        ans = d

print ans

Submission status: Runtime Error

Solution code:
k, s = list(map(int, input().split()))

p = s
factors = {}

while p > 1:
    f = False
    for i in range(2, int(p**0.5)+1):
        if p % i == 0:
            if i in factors:
                factors[i] += 1
            else:
                factors[i] = 1

            p //= i
            f = True
            break

    if not f:
        if p in factors:
            factors[p] += 1
        else:
            factors[p] = 1
        break

primes = list(factors.keys())
exp = [0] * len(primes)
upper = s/k
ans = 1

while exp[0] <= factors[primes[0]]:
    num = 1
    for i in range(len(primes)):
        num *= pow(primes[i], exp[i])

    if num == upper:
        ans = num
        break
    elif num < upper:
        ans = max(ans, num)

    index = len(primes)-1
    done = False
    while not done:
        exp[index] += 1
        if exp[index] > factors[primes[index]]:
            if index == 0:
                break
            else:
                exp[index] = 0
                index -= 1
        else:
            done = True

print(ans)

Submission status: Runtime Error

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


b = sympy.divisors(m)
# print(b)
a = m//n
# print(a)
ans = 0
for i in b:
    if i <= a:
        ans = i
print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

cand = []

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

cand.sort()

for j in cand:
    if N * j <= M:
        ans = j

print(ans)

Submission status: Runtime Error

Solution code:
def divisor(n):
    i = 1
    res = []
    for i in range(1, n**.5 + 1)
        if n%i == 0:
            res.append(i)
            if n//i not in res:
                res.append(n//i)
    res.sort(reverse=True)
    return res

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

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

N = sympy.divisors(m)

for i in range(len(N)):
    if N[i] <= m/n:
        print(N[i])
        break

Submission status: Runtime Error

Solution code:
for i in range(min(math.ceil(math.sqrt(M)), M//N), 0, -1):
  if M % i == 0:
    print(i)
    break

Submission status: Runtime Error

Solution code:
def solve():
    n, m = map(int, input().split())
    d = m // n
    p = m % n
    res = max(1, gcd(d, d + p))
    while d > 1:
        d -= 1
        q = m - n * d
        res = max(res, gcd(d, d + q))
    print(res)


solve()

Submission status: Runtime Error

Solution code:
import sympy

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

if n % m == 0:
  print(int(n/m))
  exit()
else:
  lst = sympy.divisors(m)[::-1]
  for i in lst:
    if i == 1:
      print(i)
      exit()
    if m - i*(n-1) > 0:
      if (m - i*(n-1)) % i == 0:
        print(i)
        exit()
    else:
      continue

Submission status: Runtime Error

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

a = []
for i in range(1, m):
    if m % n == 0:
        print(m // n)
        exit()
    if m % i == 0 and i * n <= m:
        a.append(i)

print(max(a))

Submission status: Runtime Error

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

def f(n,m):

	for d in range(2, m)[::-1]:
		if m % d == 0:
			if m / d >= n:
				return d		
				break

	return 1

print f(n,m)

Submission status: Runtime Error

Solution code:
[n,m] = [int(i) for i in input().split()]
if n == 1:
    print(m)
else:
    ans = -1
    #a1は高々この値
    a1_max = m // n
    for i in range(a1_max,0,-1):
        if (m - i) % i == 0 and (m - i)//i >= (n-1):
            ans = max(ans,ls[-1])
    print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
from decimal import *
 
# N以上でMを割り切ることができる最小の数nを求める　→ 答え M//n
N, M = MAP()

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
    
divisors = make_divisors(M)
print(divisors)n = divisors[bisect_left(divisors, N)]
print(M//n)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sympy
from bisect import bisect_left

def main():
    N, M = map(int, input().split())
    ans = sympy.divisors(M)
    i = bisect_left(ans,N)
    print(M//ans[i])

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def make_divisors(n):
    lower_divisors,upper_divisors=[],[]
    i=1
    while i*i<=n:
        if n%i=0:
            lower_divisors.append(i)
            if i!=n//i:
                upper_divisors.append(n//i)
        i+=1
    return lower_divisors+upper_divisors[::-1]
n,m=map(int,input().split())
array=make_divisors(m)
array.reverse()
for ele in array:
    if m//ele>=n:
        print(ele)
        exit()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
ans = 0
tmp = int(m/n)
for i in range(1,int(np.sqrt(m))):
    if m%i == 0:
        if (ans < i) and(i <= tmp):
            ans = i
print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
# from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n,m = MI()

q = m//n
r = m%n

l = [q]*(n-1)
l.append(q+r)

from math import gcd
def gcd3_list(numbers):
    return reduce(gcd, numbers)

ans = gcd3_list(l)
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
n,m = map(int,input().split())
if m%n==0:
    print(int(m//n))
    exit()
else:
    a = m%n
    b = m//n
    c = a+b
    while True:
        if gcd(b,c)!=1:
            print(gcd(b,c))
            exit()
        else:
            c -= 1
print(1)

Submission status: Runtime Error

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

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

print(i)

Submission status: Runtime Error

Solution code:
# これはエスパーですがMが素数ならNが何であってもできなさそう？未証明
# で 合成数のみっぽいので定石的に素因数分解すると
# 各項に因数をどれだけ割り振れるかみたいになる？
# -> サンプル1をみるとならなそう
# 最大公約数をgcdとすると、a*gcd*(N-1)+b*gcd = M となるのが都合よさそう こうなると右辺もgcdで割れるのでやはり約数のどれかになりそう
n, m = map(int, input().split())


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


if m % n == 0:
    print(m // n)
    exit()
else:
    x = m // n
    # 要はx以下で最大のmの約数
    lis = sorted(enum_divisor(x), reverse=true)
    for l in lis:
        if l <= x:
            print(l)
            exit()

Submission status: Runtime Error

Solution code:
# これはエスパーですがMが素数ならNが何であってもできなさそう？未証明
# で 合成数のみっぽいので定石的に素因数分解すると
# 各項に因数をどれだけ割り振れるかみたいになる？
# -> サンプル1をみるとならなそう
# 最大公約数をgcdとすると、a*gcd*(N-1)+b*gcd = M となるのが都合よさそう こうなると右辺もgcdで割れるのでやはり約数のどれかになりそう
n, m = map(int, input().split())


def enum_divisor(n):
    ret = []
    for i in range(1, int(n**0.5)):
        if n % i == 0:
            ret.append(i)
    return ret


if m % n == 0:
    print(m // n)
    exit()
else:
    x = m // n
    # 要はx以下で最大のmの約数
    lis = enum_divisor(x)
    print(lis[-1])

Submission status: Runtime Error

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

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

    ans.sort()
    return ans

d = divisor(M)
ans = 1
for x in d:
    m = M
    m -= x * (N - 1)
    if m > 0 and m % x == 0:
        ans = x

print(ans)

Submission status: Runtime Error

Solution code:
import bisect

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

n_facs_s = []
n_facs_l = []
for i in range(1, int(-(-n**0.5//1))+1):
    if m%i == 0:
        n_facs_s.append(i)
        n_facs_l.append(m//i)

n_faces = n_facs_s + n_facs_l
ind = bisect.bisect_right(n_faces, n)
print(m//n_faces[ind])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from fractions import gcd

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]]

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

prime = reversed(primes(m))

for p in prime:
    x = m - p
    if gcd(x, n-1) % p == 0:
        print(p)
        exit()

Submission status: Runtime Error

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

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

    l = int(m / n)
    for i in range(l, 1, -1):
        p, q = divmod(m, i)
        if q != 0 or p < n:
            continue

        print(i)
        break


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    from math import gcd
    n, m = map(int, input().split())
    ans = 1
    l = int(m / n)
    for i in range(2, l + 1):
        p, q = divmod(m, i)
        if q != 0 or p < n:
            continue

        ans = max(ans, i)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import itertools
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

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

l = list(range(1, M+1))
c = itertools.combinations(l, N)

z = list(filter(lambda x: sum(x) == M, c))
max_z = 0
for x in z:
    x = gcd(*x)
    max_z = max(max_z, x)

print(max_z)

Submission status: Runtime Error

Solution code:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

import math
# isprime, prime_division

def isprime(x):
    q = int(math.sqrt(x))  # int() rounds to zero
    for i in range(2,q+1):   # upto q
        if x%i == 0:
            return False
    return True

def prime_division(x):
    q = int(math.sqrt(x))
    a = []
    for i in range(2,q+1):
        ex = 0
        while x%i == 0:
            ex += 1
            x //= i
        if ex>0:
            a.append([i,ex])
    if x>q:
        a.append([x,1])
    return a

def prime_division2(x):
    q = int(math.sqrt(x))
    h = {}
    for i in range(2,q+1):
        ex = 0
        while x%i == 0:
            ex += 1
            x //= i
        if ex>0:
            h[i] = ex
    if x>q:
        h[x] = 1
    return h

def divisorlist(z): # z : output of prime_division
    if len(z)==1:
        return [z[0][0]**i for i in range(z[0][1]+1)]
    y = divisorlist(z[1:])
    s = []
    for i in range(z[0][1]+1):
        for j in y:
            s.append((z[0][0]**i)*j)
    return s

n,m = inm()
ps = divisorlist(prime_division(m))
ps2 = [x for x in ps if x<=m//n]
print(max(ps2))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

n, m = map(int, input().split())
ans = 0
nums = divisors(m)
nums.sort()
num = nums.pop(0)
while num * n <= m:
    if (m - num * n) % num == 0:
        ans = num
    num = nums.pop(0)
print(ans)

Submission status: Runtime Error

Solution code:
import sympy
N,M = map(int,input().split())
if M%N == 0:
    print(N)
else:    
    m = sympy.factorint(M)
    mm = sorted(m.items())
    mmm = reversed(mm)
    for i in mmm:
       if M/N >= i[0]:
           print(i[0])
           exit()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long

int N, M;

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> M;
    int ans = 0;
    for (int i=1; i*i<=M; i++) {
        if (M%i==0) {
            if (i*N<=M) ans = max(ans, i);
            if (i!=M/i) {
                int j = M/i;
                if (j*N<=M) ans = max(ans, j);
            }
        }
    }
    cout << ans << endl;
}

Submission status: Runtime Error

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

sq = math.sqrt(M)

for i in range(1,sq+1):
  if M % i == 0:
    if i <= math.floor(M/N):
      ans = i
    
print(int(ans))

Submission status: Runtime Error

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

if M % N != 0:
  
  a = int(M % N)
  b = (M - a) / N
  c = math.gcd(a, b)
  print(c)
else:
  print(int(M/N))

Submission status: Runtime Error

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

if M % N != 0:
  
  a = int(M % N)
  b = (M - a) / N
  c = math.gcd(a, b)
  print(c)
else:
  print(int(M/N))