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

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <boost/algorithm/string/join.hpp>
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
using namespace boost;

typedef int64_t INT;


//素数判定
bool IsPrime(INT n) {
    if (n < 2) return false;
    for (INT i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}

//n以下の素数
vector <INT> Primes(INT n) {
    vector <INT> res;
    vector <INT> primeTable;
    primeTable.resize(n + 1, -1);
    for (INT i = 2; i <= n; i++) {
        bool ok;
        if (primeTable[i] != -1) {
            ok = primeTable[i] == 1;
        } else {
            ok = IsPrime(i);
            primeTable[i] = ok ? 1 : 0;
            for (INT k = 2; k * i < primeTable.size(); k++) {
                primeTable[k * i] = 0;
            }
        }
        if (ok) {
            res.push_back(i);
        }
    }
    return res;
}

struct PrimeFactor {
    INT n;
    INT count;
};

//素因数分解
vector <PrimeFactor> PrimeFactors(INT n) {
    vector <PrimeFactor> res;
    for (auto e : Primes((INT)sqrt(n))) {
        INT count = 0;
        while (n % e == 0) {
            n /= e;
            count++;
        }
        if (count != 0) {
            res.push_back(PrimeFactor{e, count});
        }
    }
    return res;
}

INT POW(INT x, INT n) {
    INT res = 1;
    for(int i = 0;i < n;i++) {
        res *= x;
    }
    return res;
}

vector<INT>& Divisors(int index, const vector<PrimeFactor> &primes, vector<INT> &res)
{
    if(index >= primes.size()) {
        return res;
    }
    auto prime = primes[index];
    int goal = res.size();
    for (int i = 1; i < prime.count+1; ++i) {
        for(int k = 0;k < goal;k++)
        {
            res.push_back(POW(prime.n, i) * res[k]);
        }
    }
    return Divisors(index+1, primes, res);
}

//すべての約数
vector<INT> Divisors(INT n)
{
    vector<INT> divisors = {1};
    auto primes = PrimeFactors(n);
    return Divisors(0, primes, divisors);
}

void Resolve(istream &is, ostream &os) {
    INT N,M;
    is>> N >> M;
    if(N==1)
    {
        os << M;
        return;
    }
    auto divisors = Divisors(M);
    sort(divisors.begin(), divisors.end(), greater<INT>());
    for(auto e: divisors)
    {
        if(e * N <= M)
        {
            os << e;
            return;
        }
    }
}

#if !TEST
int main() { cin.tie(0); ios::sync_with_stdio(false); Resolve(cin, cout); cout.flush(); return 0;}

#endif