1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 #include #include #include #include using namespace std; namespace { template void generate(vector const& primes, T m, F&& f, T x=1, int i=0) { if (!f(x)) return; int k = primes.size(); while (i < k) { auto p = primes[i]; if (x > m / p) break; generate(primes, m, f, x * p, i); ++i; } } long long solve(vector primes, long long m) { sort(primes.begin(), primes.end()); vector primes1, primes2; int k = primes.size(); for (int i = 0; i < k; ++i) { if (i < 5) primes1.emplace_back(primes[i]); else primes2.emplace_back(primes[i]); } vector small; small.reserve(300000); generate(primes1, m, [&](long long x) { small.emplace_back(x); return true; }); sort(small.begin(), small.end()); long long res = 0; generate(primes2, m, [&](long long x) { auto y = m / x; if (x * y <= res) return false; auto it = lower_bound(small.begin(), small.end(), y + 1); if (it != small.begin()) { auto it2 = prev(it); res = max(res, x * *it2); } return true; }); return res; } } int main() { iostream::sync_with_stdio(false); cin.tie(nullptr); int n; long long m; cin >> n >> m; vector primes(n); for (int& p: primes) cin >> p; cout << solve(move(primes), m) << endl; return 0; }