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
#include <algorithm>
#include <stdio.h>

bool ok(unsigned long long a, int p[], int n) {
    unsigned long long k = a;
    for (int i = 0; i < n; i++) {
        while (k % p[i] == 0) {
            k = k / p[i];
        }
    }
    return k == 1;
}

int main() {
    int k;
    unsigned long long N;
    scanf("%d %llu", &k, &N);

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

    std::sort(p, p + k);

    unsigned long long c[k];

    for (int i = 0; i < k; i++) {
        if (N < p[i]) {
            c[i] = 1;
        } else {
            c[i] = N - N % p[i];
        }
    }

    while (true) {
        for (int i = 0; i < k; i++) {
            if (ok(c[i], p, k)) {
                printf("%llu\n", c[i]);
                return 0;
            } else {
                c[i] = c[i] - p[i];
            }
        }
    }
}