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
#include <iostream>
using namespace std;

bool f(long long x, long long *a, long long k) {
	for(int i = 0; i < k; i++) {
		if(x == a[i]) {
			return true;
		}
		else if(x%a[i] == 0) {
			return f(x/a[i], a, k);
		}
	}
	return false;
}

int main() {
	long long k, N;
	cin >> k >> N;

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

	long long current = N;

	while(current > 0) {
		for(int i = 0; i < k; i++) {
			if(f(current, a, k)) {
				cout << current;
				goto FINISHED;
			}
		}
		current--;
	}

	FINISHED:
	if(current == 0) cout << 0;
	return 0;
}