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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
#define LL long long
#define PB push_back

#define GEN_LVLS 6

int power_counter = 0;
LL powers[960000];
inline void new_power(LL a) {
  powers[power_counter++] = a;
}

LL N;
vector<int> P;
LL score = 1;

bool can_multiply(LL a, LL b) {
  return a <= N / b;
}

void input();
void genrec(LL, int);
void binrec(LL, int, int);
void solve();

int main() {
  input();

  solve();

  printf("%lld\n", score);
}

void input() {
  int k, p;
  scanf("%d %lld", &k, &N);
  for (int i = 0; i < k; ++i) {
    scanf("%d", &p);
    P.PB(p);
  }
  sort(P.begin(), P.end());
}

void genrec(LL act, int level) {
  while (can_multiply(act, P[level])) {
    if (level + 1 < GEN_LVLS && level + 1 < P.size()
        && can_multiply(act, P[level + 1])) {
      genrec(act, level + 1);
    }
    
    act *= P[level];
    new_power(act);
  }
}

void solve() {
  new_power(1);
  genrec(1, 0);
  sort(powers, powers + power_counter);

  for (auto p : powers) {
    score = max(score, p);
  }

  if (P.size() > GEN_LVLS) {
    binrec(1, GEN_LVLS, power_counter - 1);
  }
}

void binrec(LL act, int level, int B) {
  int A, C;
  while (can_multiply(act, P[level])) {
    if (level < P.size() - 1
        && can_multiply(act, P[level + 1])) {
      binrec(act, level + 1, B);
    }

    act *= P[level];

    A = 0;
    if (!(can_multiply(act, powers[B]) && act * powers[B] <= score)) {
      while (A != B) {
        C = (A + B + 1) / 2;
        if (can_multiply(act, powers[C])) {
          A = C;
        } else {
          B = C - 1;
        }
      }
    }

    score = max(score, act * powers[A]);
  }
}