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
#include <bits/stdc++.h>
using namespace std;

int main() {
    int k, p;
    long long a, b, n;
    vector<int> P;
    scanf("%d %lld", &k, &n);
    for (int i = 0; i < k; ++i) {
        scanf("%d", &p);
        P.push_back(p);
    }
    while (n > 0) {
        a = n;
        for (int i = 0; i < (int)P.size(); ++i) {
            while (true) {
                b = a / P[i];
                if (b * P[i] != a) {
                    break;
                }
                a = b;
            }
        }
        if (a == 1) {
            printf("%lld\n", n);
            return 0;
        }
        --n;
    }
    return 0;
}