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
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <list>

std::vector<int> primes(100);

long long best = 0;

void genNumbers(long long current, int prime_idx, int k, int n) {
    if (current > n)
        return;
    best = std::max(best, current);
    if (prime_idx == k)
        return;
    int prime = primes[prime_idx];
    genNumbers(current, prime_idx + 1, k, n);
    while (current <= n) {
        current *= prime;
        genNumbers(current, prime_idx + 1, k, n);
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    int k, n;
    std::cin >> k >> n;
    for (int i = 0; i < k; i++)
        std::cin >> primes[i];

    genNumbers(1, 0, k, n);
    std::cout << best;

}