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
// Beniamin Gajecki
#include <iostream>
#include <cmath>
#include <vector>

bool getFirstFactors(unsigned _a, std::vector<unsigned short> _b)
{
    if(_a > 1)
    {
        for(int i = _b.size() - 1; i>=0; --i)
        {
            if(_a%_b[i]==0)
            {
                _a /= _b[i];
                return getFirstFactors(_a, _b);
            }
        }
        return false;
    }
    else
        return true;
}

int main()
{
    unsigned k, n;
    std::cin>>k>>n;
    if((k >= 1) && ((1 <= n) &&(n <= pow(10, 18))))
    {
        std::vector<unsigned short> ilo;
        unsigned short x;
        for(unsigned i = 0; i<k; ++i)
        {
            std::cin>>x;
            if((2 <= x) && (x <= 100))
                ilo.push_back(x);
            else
                return 1;
        }
        for(unsigned i = n; i>1; --i)
        {
            if(getFirstFactors(i, ilo))
            {
                std::cout<<i;
                return 0;
            }
        }
        return 1;
    }
    return 1;
}