Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(5000000)

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):
    ps = []
    i = 0
    n = len(primes)
    while (x > 1) and (i < n):
        p = primes[i]
        while x % p == 0:
            x /= p
            ps.append(p)
        i += 1
    if x > 1:
        ps.append(p)
    res = {}
    for p in ps:
        if not p in res:
            res[p] = 0
        res[p] += 1
    return res

def f(x, d, n, m, ps):
    if x >= n:
        return x
    if d >= len(ps):
        return m
    p, num = ps.items()[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, 0, n, m, ps)
    assert m % q == 0, (m, q)
    p = m // q
    return p

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

Fixed submission:
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))

Buggy python submission (verdict: Runtime Error):
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):
    ps = []
    i = 0
    n = len(primes)
    while (x > 1) and (i < n):
        p = primes[i]
        while x % p == 0:
            x /= p
            ps.append(p)
        i += 1
    if x > 1:
        ps.append(p)
    res = {}
    for p in ps:
        if not p in res:
            res[p] = 0
        res[p] += 1
    return res

def f(x, d, n, m, ps):
    if x >= n:
        return x
    if d >= len(ps):
        return m
    p, num = ps.items()[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, 0, n, m, ps)
    assert m % q == 0, (m, q)
    p = m // q
    return p

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

Fixed submission:
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))