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
#include <iostream>
#include <vector>


int main()
{
    std::ios_base::sync_with_stdio(0);

    //
    int K = 0;
    long long N = 0;

    std::cin >> K;
    std::cin >> N;

    std::vector<int> P(static_cast<size_t>(K));
    for (size_t i = 0; i < static_cast<size_t>(K); ++i){
        std::cin >> P[i];
    }

    //
    for (long long i = N; i > 0; --i)
    {
        long long j = i;

        for (const auto &p : P)
        {
            while (j % p == 0) {
                j /= p;
            }

            if (j == 1) {
                printf("%lld\n", i);
                return 0;
            }
        }
    }

    return 0;
}