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
#include <cstdio>
#include <vector>
#include <stdint.h>
#include <algorithm>
using namespace std;

int k;
uint64_t N;
vector<uint8_t> P;
vector<vector<uint64_t> > PP;
uint64_t global_result;

void calculate(uint64_t result, uint64_t restN, int z) {
    while (z<k-1 && restN<P[z]) ++z;
    for (int i=PP[z].size()-1; i>=0; --i) {
        if (restN < PP[z][i]) continue;
        uint64_t new_result = result * PP[z][i];
        uint64_t new_restN = restN / PP[z][i];
        if (z == k-1) {
            if (global_result < new_result) global_result = new_result;
        } else calculate(new_result, new_restN, z + 1);
    }
}

int main() {
    scanf("%d %llu", &k, &N); P.resize(k); PP.resize(k);
    for(int i=0; i<k; ++i) scanf("%d", &P[i]);
    sort(P.begin(), P.end());
    for (int i=0; i<k; ++i) {
        PP[i].push_back(1);
        while (PP[i].back() <= N / P[i]) {
            PP[i].push_back(PP[i].back() * P[i]);
        }
    }

    global_result = 1;
    calculate(1, N, 0);
    printf("%llu\n", global_result);
}