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
#include <iostream>
#include <vector>
#include <set>

using namespace std;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(0);

	ll n;
	int k;
	cin >> k >> n;
	vector<ll> a(k);
	set<ll> out;
	set<ll> prev;

	prev.insert(1);

	for (int i = 0; i < k; i++) cin >> a[i];

	for (int i = 0; i < k; i++) {
		ll b = a[i];
		for (auto it = prev.begin(); it != prev.end(); it++) {
			ll tmp = *it;
			while (tmp <= n) {
				out.insert(tmp);
				tmp *= b;
			}
		}
		out.swap(prev);
		out.clear();
	}

	cout << *(--prev.end()) << endl;

	return 0;
}