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())
if M%N==0:
  print(M//N)
else:
  s=M//N
  if s<100000:
    ans=1
    while s!=1:
      if M%s==0:
        ans=s
        break
      s-=1
    print(ans)
  else:
    rM=M**(1/2)
    s=N
    ans=1
    while s<=rM:
      if M%s==0:
        ans=M//s
        break
      s+=1
    else:
      s=N
      while s!=1:
        if M%s==0:
          ans=s
          break
        s-=1
    print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
from bisect import bisect_right
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)
print(D[bisect_right(D,m/n)-1])

Submission status: Accepted

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

import bisect

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

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

y.sort()
print(M // y[bisect.bisect_left(y, N)])

Submission status: Accepted

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

ans = 0
for x in range(1, int(M ** 0.5) + 1):
    if M % x != 0:
        continue
    else:
        x1, x2 = x, M // x
        if M // x1 >= N:
            ans = max(ans, x1)
        if M // x2 >= N:
            ans = max(ans, x2)

print(ans)

Submission status: Accepted

Solution code:
import bisect
import math

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

divisors=[]
for i in range(1,math.floor(math.sqrt(M))+1):
    if M%i==0:
        divisors.append(i)
        divisors.append(M//i)
        
divisors.sort()
print(M//divisors[bisect.bisect_left(divisors,N)])

Submission status: Accepted

Solution code:
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    
    table.sort()
    return table

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

div = divisor(M)

for i in range(len(div)):
    if div[i] <= M // N:
        res = div[i]
            
print(res)

Submission status: Accepted

Solution code:
def solve(string):
    n, m = map(int, string.split())
    d = [i for i in range(1, int(m**0.5) + 1) if m % i == 0]
    d.extend([m // i for i in d])
    return str(max([i for i in d if m // i >= n]))


if __name__ == '__main__':
    print(solve(input()))

Submission status: Accepted

Solution code:
def divisionize(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 = sorted(divisors) # ソートが必要であれば
    return divisors
n,m = map(int, input().split())
dm = divisionize(m)
print(max([d for d,d_ in zip(dm,dm[::-1]) if d_>=n]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n, m = map(int, input().split())

def factorize(m):
    c = Counter()
    t = 2
    while t**2 <= m:
        if m % t:
            t += 1
            continue
        while not m%t:
            c[t] += 1
            m //= t
    if m > 1:
        c[m] += 1
    return c
yakusu = [1]
for key, value in factorize(m).items():
    next_yakusu = []
    for i in range(value+1):
        for j in yakusu:
            next_yakusu.append(j*key**i)
    yakusu = next_yakusu

ans = 1
for i in yakusu:
    if n <= m//i:
        ans = max(ans, i)
print(ans)

Submission status: Accepted

Solution code:
import sys, os, random, math

def rd():
        return sys.stdin.readline().rstrip()

def rdi():
        return [ int(x) for x in rd().split() ]

def solve(N, M):
        L = math.sqrt(M) + 0.5
        i = N
        while i <= L:
                if M % i == 0:
                        return M / i
                i = i + 1
        i = N-1
        while i >= 1:
                if M % i == 0 and M / i >= N:
                        return i
                i = i - 1
        assert 0

N, M = rdi()
print solve(N, M)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
n2 = int((M ** 0.5) + 1)
divisor = []
for i in range(1, n2 + 1):
    if M % i == 0:
        divisor.append(i)
        divisor.append(M // i)

#print(divisor)
ans = min(filter(lambda e:e >= N, divisor))
#print(ans)
ans = M // ans
print(ans)

Submission status: Accepted

Solution code:
import math

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

sup = math.ceil(m**0.5)

ans = 1

for i in range(1,sup+1):
    if m%i==0:
        j = m//i
        if j>=n and i>ans:
            ans = i
        if i>=n and j>ans:
            ans = j

print(ans)

Submission status: Accepted

Solution code:
#nの約数列挙
def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            ass.append(n//i)
    return ass #sortされていない
n, m = map(int,input().split())
divs = list(reversed(sorted(divisor(m))))
for i in divs:
    if m//i >= n:
        print(i)
        break

Submission status: Accepted

Solution code:
import math

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

for p in range(1, int(math.sqrt(m)) + 1):
    if m % p == 0:
        q = m // p
        
        if p >= n and q > pq_max:
            pq_max = q
            
        if q >= n and p > pq_max:
            pq_max = p
        
print(pq_max)

Submission status: Accepted

Solution code:
import math

N,M = map(int,input().split())
A = []
n = 0
if N == 1:
    print(M)
else:
    ans = 1
    for i in range(1, int(math.sqrt(M))+1):
        if (M % i == 0):
            if i <= M//N:
                A.append(i)
            if M/i <= M//N:
                A.append(int(M/i))
    A.sort()
    print(A[-1])

Submission status: Accepted

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

import math
import sys
import heapq
from operator import itemgetter
import itertools
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':


def divisors(n, m):
	for i in range(m//n, 0, -1):
		if m % i == 0:
			return(i)


N, M = map(int, input().rstrip().split())
print(divisors(N, M))

Submission status: Accepted

Solution code:
import math
n,m = map(int, input().split())
factors = []
comp = m//n
for i in range(int(math.sqrt(m)),0,-1):
    if(m%i==0):
        factors.insert(0,i)
        factors.append(m//i)
for item in factors[::-1]:
    if (item <= comp):
        print(item)
        exit(0)

Submission status: Accepted

Solution code:
import math

def main():
    N, M = list(map(int, input().split(' ')))
    s = min(math.ceil(math.sqrt(M)), M//N)
    ret = []
    while s > 0:
        if M%s == 0:
            a = M//s
            ret.append(a)
            ret.append(s)
        s -= 1
    print(max([s for s in ret if s <= M//N]))



if __name__ == '__main__':
    main()

Submission status: Accepted

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

kmax = M // N
sqrt = int(M**0.5)

k = 0
for i in range(sqrt)[::-1]:
    k1, k2 = i+1, M//(i+1)
    if M % k2 == 0 and k2 <= kmax:
        k = max(k, k2)
    elif M % k1 == 0 and k1 <= kmax:
        k = max(k, k1)

print(k)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n, m = map(int, input().split())
array = []
for i in range(1, int(math.sqrt(m)+1)):
    if m % i == 0:
        array.append([i, m//i])

diff = float("inf")
res = 0
for i, j in array:
    if i >= n:
        res = max(res, j)
    if j >= n:
        res = max(res, i)
print(res)

Submission status: Accepted

Solution code:
import sys

def main():
  input = sys.stdin.readline
  N, M = map(int, input().split())
  H = 1
  for i in range(int(M//N), 1, -1):
    if M % i == 0:
      H = i
      break

  print(H)

if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# できなかった
# a1,...,anがdivisorで割り切れる、すなわちdivisorはMの約数である
n,m=map(int,input().split())

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

divisors.sort(key=lambda x:-x)
# print(divisors)
for d in divisors:
    if d<=m//n:
        print(d)
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# Luis Yoichi Morales January 2019

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

ans = 1
x = 1
a = []

while x * x <=M:
 if M%x==0:
  a.append(x)
  a.append(M/x)
  #print x, M/x
 x+=1
 

#print x, a
for i in a:
 if M/i >= N:
  ans = max(ans,i)
print ans

Submission status: Accepted

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


def init() -> None:
    i = 1
    while i ** 2 <= m:
        if m % i == 0:
            candidates.add(i)
            candidates.add(m // i)
        i += 1


def main() -> None:
    init()
    ans = 0
    for candidate in candidates:
        if candidate * n <= m:
            ans = max(ans, candidate)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

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


ans = 0
for i in range(1, math.ceil(math.sqrt(m))+1):
    if m % i == 0:
        if min(i, m//i) >= n:
            ans = max(ans, max(i, m//i))
        elif max(i, m//i) >= n:
            ans = max(ans, min(i, m//i))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

res = []
for i in range(1, int(math.sqrt(M))+1):
    if M % i == 0:
        res.append(i)
        res.append(M//i)
res.sort()
print(res[bisect.bisect_right(res, M//N)-1])

Submission status: Accepted

Solution code:
import numpy as np
flag = True
N, M = map(int, input().split())
ans = 0
for i in range(1, int(np.sqrt(M)) + 2):
    if M % i == 0:
        if min(M // i, i) >= N:
            ans = max(ans, max(M // i, i))
        elif max(M // i, i) >= N:
            ans = max(ans, min(M // i, i))

print(ans)

Submission status: Accepted

Solution code:
def s(n):
    return[m(t)for t in d(f(n))]
def f(n):
    l=[]
    b,e=2,0
    while b*b<=n:
        while not n%b:
            n//=b
            e+=1
        if e:
            l.append((b,e))
        b,e=b+1,0
    if n>1:
        l.append((n,1))
    return l
def d(l):
    b,e=l.pop()
    p=d(l)if l else[[]]
    v=[[(b,k)]for k in range(e+1)]
    return[s+t for s in p for t in v]
def m(l):
    a=1
    for b,e in l:
        a*=b**e
    return a
N,M=map(int,input().split())
if M<2:print(1);exit()
a=0
for i in sorted(s(M))[::-1]:
    if M//i>=N:
        a=i
        break
print(a)

Submission status: Accepted

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

class Prime:
    seed_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

    def is_prime(self, n):
        is_prime_common = self.is_prime_common(n)
        if is_prime_common is not None:
            return is_prime_common

        if n < 2000000:
            return self.is_prime_bf(n)
        else:
            return self.is_prime_mr(n)

    def is_prime_common(self, n):
        if n == 1: return False
        if n in Prime.seed_primes: return True
        if any(map(lambda x: n % x == 0, self.seed_primes)): return False

    def is_prime_bf(self, n):
        for k in range(2, int(math.sqrt(n)) + 1):
            if n % k == 0:
                return False
        return True

    def is_prime_mr(self, n):
        d = n - 1
        while d % 2 == 0:
            d //= 2

        witnesses = self.get_witnesses(n)

        for w in witnesses:
            y = pow(w, d, n)

            while d != n - 1 and y != 1 and y != n - 1:
                y = (y ** 2) % n
                d *= 2

            if y != n - 1 and d % 2 == 0:
                return False

        return True

    def get_witnesses(self, num):
        def _get_range(num):
            if num < 2047:
                return 1
            if num < 1373653:
                return 2
            if num < 25326001:
                return 3
            if num < 3215031751:
                return 4
            if num < 2152302898747:
                return 5
            if num < 3474749660383:
                return 6
            if num < 341550071728321:
                return 7
            if num < 38255123056546413051:
                return 9
            return 12

        return self.seed_primes[:_get_range(num)]

    def gcd(self, a, b):
        if a < b:
            a, b = b, a
        if b == 0:
            return a
        while b:
            a, b = b, a % b
        return a

    @staticmethod
    def f(x, n, seed):
        p = Prime.seed_primes[seed % len(Prime.seed_primes)]
        return (p * x + seed) % n

    def find_factor(self, n, seed=1):
        if self.is_prime(n):
            return n

        x, y, d = 2, 2, 1
        count = 0
        while d == 1:
            count += 1
            x = self.f(x, n, seed)
            y = self.f(self.f(y, n, seed), n, seed)
            d = self.gcd(abs(x - y), n)

        if d == n:
            return self.find_factor(n, seed+1)
        return self.find_factor(d)

    def find_factors(self, n):
        primes = {}
        if self.is_prime(n):
            primes[n] = 1
            return primes

        while n > 1:
            factor = self.find_factor(n)

            primes.setdefault(factor, 0)
            primes[factor] += 1

            n //= factor

        return primes

prime = Prime()

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

    prime = Prime()

    factors = prime.find_factors(M)

    max_g = M // N
    g = 1
    d = [1]
    for p, n in factors.items():
        nd = []
        for v in d:
            for k in range(n + 1):
                m = p ** k
                if v * m <= max_g:
                    g = max(g, v * m)
                    nd.append(v * m)
                else:
                    break
        d = nd


    print(g)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

S = list(map(int,input().split()))
N = S[0]
M = S[1]
div = list()
z = math.sqrt(M)
z = math.ceil(z)

for x in range(1,z):
    if M % x == 0:
        div.append(x)
        div.append(M//x)
div.append(M)
div.append(N)

sorted_div = sorted(div)
n = sorted_div.index(N)

y =sorted_div[n+1]

ans = M // y

print(ans)

Submission status: Accepted

Solution code:
#nの約数列挙
def devisor(n):
    ans = []
    for i in range(1,int(n**0.5)+2):
        if n%i == 0:
            ans.append(i)
            ans.append(n//i)

    return ans       


N,M = list(map(int,input().split()))
a = devisor(M)
a.sort(reverse = True)

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

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    if n == 1:
        print(m)
        return
    i = 1
    ans = 1
    while i*i <= m:
        if m % i != 0:
            i += 1
            continue
        a = i
        if m // i >= n:
            ans = max(ans, i)
        if m // (m // i) >= n:
            ans = max(ans, m // i)
        i += 1
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    if N == 1:
        print(M)
    else:
        ans = 0
        for i in range(1, int(M ** 0.5)):
            if M % i != 0:
                continue
            if M >= i * N:
                ans = max(i, ans)
            if M >= M // i * N:
                ans = max(M // i, ans)

        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(1, a + 1):
    if m % i == 0:
        ans = i
        if (m // i) > i and (m // i) <= a:
            ans = m // i
            break
        
print(ans)

Submission status: Accepted

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

upper = m//n
ans = 0
for i in range(1, upper+1):
    if m % i == 0:
        ans = i
        if (m // i) > i and (m // i) <= upper:
            ans = m // i
            break

print(ans)

Submission status: Accepted

Solution code:
import math
import bisect


def all_divisor(n):
  i = 1
  divisor_small = []
  divisor_large = []
  if n == 1:
    return [1]
  else:
    while i * i <= n:
      if n % i == 0:
        divisor_small.append(i)
        divisor_large.append(n // i)
      i += 1
  divisor_large.reverse()
  divisor = divisor_small + divisor_large 
  return divisor

n,m = map(int, input().split())
divisor = all_divisor(m)
max_div = m // n
insert_index = bisect.bisect(divisor,max_div)
print(divisor[insert_index-1])

Submission status: Accepted

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

i=1
while i <= M//N: 
  if M % i == 0:
    maxg = i
    if M//i <= M//N:
      maxg = M // i
      break
  i += 1

print(maxg)

Submission status: Accepted

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

for i in range(1, a + 1):
    if m % i == 0:
        ans = i
        
        if (m // i) > i and (m // i) <= a:
            ans = m // i
            break
        
print(ans)

Submission status: Accepted

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

ans = 1
for g in range(1, int(M ** 0.5) + 1):
    if M % g == 0 and M / g >= N:
        ans = max(ans, g)
    
    if M % g == 0:
        g2 = M // g
        if M % g2 == 0 and M / g2 >= N:
            ans = max(ans, g2)
print(ans)

Submission status: Accepted

Solution code:
import math as m
N,M = map(int,input().split())
divisor = []
for i in range(1,m.floor(pow(M,1/2)) + 1):
  if M % i == 0:
    divisor.append(i)
    divisor.append(M // i)
ans = 1
for e in divisor:
  if e > ans and e <= M // N:
    ans = e
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
divisors = []
for i in range(1,m+1):
    if i * i > m:
        break
    if i * i == m:
        divisors.append(i)
        break
    if m % i == 0:
        divisors.append(i)
        divisors.append(m // i)
ans = filter(lambda d: d <= m//n, divisors)
print(max(ans))

Submission status: Accepted

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

def yakusu(m):
    y = []
    for i in range(1, math.ceil(math.sqrt(m))+1):
            if m % i == 0:
                y.extend([i, m//i])
    return y

if M % N == 0:
    print(M//N)
else:
    yaku = sorted(yakusu(M))
    for yi in yaku:
        if yi < N:
            continue
        else:
            break
    print(M//yi)

Submission status: Accepted

Solution code:
primes = []
MAX_NUM = 100000
is_prime = [True] * MAX_NUM
is_prime[0] = False
is_prime[1] = False
for num in range(MAX_NUM):
    if is_prime[num]:
        primes.append(num)
        for j in range(2*num, MAX_NUM, num):
            is_prime[j] = False

def do_prime_factorization(x):
    res = {}
    for p in primes:
        if x == 1:
            break
        while x % p == 0:
            x /= p
            if not p in res:
                res[p] = 0
            res[p] += 1
    if x > 1:
        res[x] = 1
    return res.items()

def f(x, d, n, m, ps):
    if x >= n:
        return x
    if d < 0:
        return m
    p, num = ps[d]
    res = m
    for i in range(num+1):
        y = x * (p**i)
        res = min(res, f(y, d-1, n, m, ps))
    return res

def solve(n, m):
    ps = do_prime_factorization(m)
    q = f(1, len(ps)-1, n, m, ps)
    p = m // q
    return p

n, m = map(int, raw_input().split())
print(solve(n, m))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
candidates = []
for p in range(1, max(int(M ** 0.5) + 1, N + 1)):
    if M % p == 0:
        if M // p >= N:
            # p * (M // p = a1+a2+.. >= N) = M
            candidates.append(p)
        if p >= N:
            # (M // p) * (p = a1+a2+.. >= N) = M
            candidates.append(M // p)
print(max(candidates))

Submission status: Accepted

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

upper=M/N
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

fct = factorize(M)
if fct==[]:
    print 1
    exit()

Ans=1
for div in divisorize(fct):
    if num(div)<=upper:
        Ans=max(Ans,num(div))
   
print Ans

Submission status: Accepted

Solution code:
from math import sqrt

N, M = map(int, input().split())
ans = max(M // i if M // i <= M / N else i  for i in range(1, int(sqrt(M)) + 1) if M % i == 0 and i <= M / N)
print(ans)

Submission status: Accepted

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

ans=0

if n==1:
  print(m)
else:
  a=int(m**0.5)

  for i in range(1,a):
    if m%i==0:
      if i*n<=m:
        ans=max(ans,i)
      if (m//i)*n<=m:
        ans=max(ans,m//i)
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

from math import sqrt

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

for k in range(1, int(sqrt(M)) + 1):
    if M % k == 0:
        if k <= M / N:
            ans = max(ans, k)
        if M/k <= M/N:
            ans = max(ans, M//k)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N, M = map(int, input().split())
yakusuu = [] 
for i in range(int(math.sqrt(M))):
  if M%(i+1) == 0:
    yakusuu +=[i+1]
    yakusuu +=[M//(i+1)]
yakusuu.sort(reverse=1)

for p in yakusuu:
  if p <= M/N:
    print(p)
    break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

"""
参考：http://drken1215.hatenablog.com/entry/2018/11/06/120600
　　　https://emtubasa.hateblo.jp/entry/2018/10/06/224022
・約数とか。理解は出来たものの、自分で気付けるにはどうすれば…。
・この前作ったけど使えなかった約数列挙ライブラリが役に立った。
"""

from math import sqrt

def num_div_set2(N):
    # 1とその数はデフォで入れとく
    s = {1, N}
    # 終点はルート切り捨て+1
    end = int(sqrt(N)) + 1
    for i in range(2, end+1):
        # 割り切れるなら、iとN/iを追加
        if N % i == 0:
            s.add(i)
            s.add(N // i)
    return s

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

ans = 1
for d in num_div_set2(M):
    # aNを全てdとするより大きいのは、Mに収まらないからダメ
    # 逆にそれ以下の約数なら、全dの最後の1つだけ調整すればどうにでも作れるからOK
    if d * N <= M:
        ans = max(d, ans)
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
a, b = 1, M
divisor = []
while a <= b:
    if a * b == M:
        divisor.append(a)
        divisor.append(b)
    a = M // b + 1
    b = M // a
divisor.sort()
for i in divisor:
    if i >= N:
        print(M // i)
        break

Submission status: Accepted

Solution code:
import itertools
import math

#方針: A*B = B (A,Bは整数, A>=N)となる最大のBを探せばいい

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

P = []
F = []
M_ = M
for n in range(2, int(math.sqrt(M))+1):
    num = 0
    while M_ % n == 0:
        M_ /= n
        num +=1
    if num != 0:
        P.append(n)
        F.append(num)
if M_ != 1:
    P.append(M_)
    F.append(1)

min_A = M
for F_ in itertools.product(*list(map(lambda i: range(i+1), F))):
    A = 1
    for p,f in zip(P,F_): A *= pow(p,f)
    if A >=N and A < min_A: min_A = A

print(int(M/min_A))

Submission status: Accepted

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

def yaku(N):
    res = []
    for i in range(1, round(N**(1/2)) + 3 ):
        if N%i == 0:
            res.append(i)

    res2 = [N//i for i in res]
    res = list(set(res + res2))
    return res


import bisect

L = yaku(M)

L.sort()
ii = bisect.bisect_left(L,N)

print(M//L[ii])

Submission status: Accepted

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python

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

# N splited by number of M 
import math
plist = [2]
for i in range(3, int(1e5+1)):
    ok = True
    for j in plist:
        if j > math.sqrt(i):
            break   
        elif i % j == 0:
            ok = False
            break
    if ok:
        plist.append(i)

# print(plist)

## 

prime_pair = {}

def cnt_power(n, p):
    if p < 2:
        raise "p is smaller than 2."
    if n >= p and n % p == 0:
        return 1 + cnt_power(int(n/p), p)
    else:
        return 0
        
def fac(N):
    global prime_pair
    for p in plist:
        if N % p == 0:  
            # print(N,p)
            # prime_pair[p = ] = (p, cnt_power(N, p))
            prime_pair[p] = cnt_power(N, p)

# print(fac(M))
fac(M)

import copy
divisor = []
init_nowpair = {}
for k in prime_pair:
    # print("prime pair: ", k, prime_pair[k])
    init_nowpair[k] = 0


def makedivisor(prime_pair, now_pair):
    # print(now_pair)
    multi = 1
    for np in now_pair:
        multi *= int(pow(np, now_pair[np]))
    #     print("\tmulti:", multi)
    # print("multi:", multi)
    if multi > M:
        return 
    else:
        if not multi in divisor:
            divisor.append(multi)
        else:
            return 
    

    for np in now_pair:
        if prime_pair[np] > now_pair[np]:
            now_pair2 = copy.deepcopy(now_pair)
            now_pair2[np] += 1
            makedivisor(prime_pair, now_pair2)
makedivisor(prime_pair, init_nowpair)            
divisor.sort()
# print(divisor)

maxx = 0
for d in divisor:
    if M % d == 0 and int(M/d) >= N:
        maxx = max(maxx, d)

print(maxx)
        
    
# for k in prime_pair:
#     print(k,prime_pair[k])





# maxx = 0
# maxlen = 0
# for i in range(3, int(1e9)):
#     if i % int(1e3) == 0:
#         print(i)
#         print(maxx, maxlen)

#     prime_pair = {}
#     fac(i)
#     maxlen = max(maxlen, len(prime_pair))
#     for k in prime_pair:
#         maxx = max(maxx, prime_pair[k])

Submission status: Accepted

Solution code:
import math

N,M = list(map(int,input().strip().split()))
ans = 1
i = 0

def is_prime(num):
    if num < 2:
        return False
    if num == 2 or num == 3 or num == 5:
        return True
    if num % 2 == 0 or num % 3 == 0 or num % 5 == 0:
        return False

    prime = 7
    step = 4
    num_sqrt = math.sqrt(num)
    while prime <= num_sqrt:
        if num % prime == 0:
            return False
        prime += step
        step = 6 - step

    return True

if is_prime(M) == False:
    while M//2 >= N+i:
        if M%(N+i) == 0:
            ans = M//(N+i)
            break
        else:
            i += 1

print(ans)

Submission status: Accepted

Solution code:
import math

def factoring(x):
    ans = []
    for i in range(1, int(math.sqrt(x))+1):
        if x%i == 0:
            ans.append(i)
            ans.append(x // i)
    return sorted(ans)

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

facts = factoring(m)
for i in facts[::-1]:
    if i <= int(m/n):
        print(i)
        exit()

Submission status: Accepted

Solution code:
import math

def factoring(x):
    ans = []
    for i in range(1, int(math.sqrt(x))+1):
        if x%i == 0:
            ans.append(i)
            ans.append(x // i)
    return sorted(ans)

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

facts = factoring(m)
ans = 1
for i in facts[::-1]:
    if i <= int(m/n):
        print(i)
        exit()
print(ans)