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
75
#include <cstdio>
#include <vector>

using namespace std;

long long n;
int k;
vector<int> pier;

bool is_good(long long num){
	for(int i = 0; i < k; ++i){
		while(true){
			if(num % pier[i] == 0)
				num /= pier[i];
			else break;
		}
	}
	if(num == 1) return true;
	return false;
}

const long long CUT = 10000000000000666;
const int MAX = 48;
long long best = 1;
long long dist = 1000000000000000666;

void rec(int pos, long long num){
	if(pos == k){
		if(n - num >= 0 && n - num < dist){
			dist = n - num;
			best = num;
		}
		return;
	}

	for(int i = 0; i < MAX; ++i){
		rec(pos+1, num);
		if(num > CUT) return;
		num *= pier[pos];
	}
	rec(pos+1, num);
}

int main(){

	scanf("%d %lld", &k, &n);

	pier.resize(k);

	for(int i = 0; i < k; ++i){
		scanf("%d", &pier[i]);
	}

	if(n == 1){
		printf("1\n");
		return 0;
	}

	if(k < 4){
		rec(0, 1);
		printf("%lld\n", best);
		return 0;
	}

	while(true){
		if(is_good(n)){
			printf("%lld\n", n);
			return 0;
		}
		--n;
	}


	return 0;
}