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

using namespace std;

typedef long long int LL;

const short int MAX_K = 25;

vector<LL> v[MAX_K];
short int input[MAX_K];
LL n, result;
short int k;

void foo(int cur, LL nr) {
  result = max(result, nr);
  for (int j = 0; j < v[cur].size(); ++j) {
    if (v[cur][j] * nr < 0 || v[cur][j] * nr > n) {
      return;
    } else if (cur - 1 >= 0) {
      foo(cur - 1, v[cur][j] * nr);
    } else {
      result = max(result, v[cur][j] * nr);
    }
  }
}

int main () {
  scanf("%d %lld", &k, &n);
  for (int i = 0; i < k; ++i) {
    scanf("%d", &input[i]);
  }
  sort(input, input + k);
  for (int i = 0; i < k; ++i) {
    LL nr = input[i];
    v[i].push_back(1LL);
    while (nr < n) {
      if (nr < 0) {
        break;
      }
      v[i].push_back(nr);
      nr *= input[i];
    }
  }
  if (k == 1) {
    printf("%lld\n", v[0][v[0].size() - 1]);
    return 0;
  }
  for (int j = 0; j < v[k - 1].size(); ++j) {
    foo(k - 2, v[k - 1][j]);
  }
  printf("%lld\n", result);
  return 0;
}