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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <functional>


using namespace std;


typedef long long unsigned int  llu;


static int iPrimes;

static llu * pLast;

static llu iN, iCnt;

static llu aPrimes[25 * 60];


static void ReadData()
{
    int k = 0;

    iCnt = 0;

    scanf("%d", &iPrimes);

    scanf("%lld", &iN);

    for (int i = 0; i < iPrimes; ++i)
    {
        llu x;

        scanf("%lld", &x);

        for (llu y = x; y <= iN; y *= x)
        {
            aPrimes[k++] = y;
        }
    }

    iPrimes = k;

    pLast = aPrimes + iPrimes - 1;
}


static llu FindTheLargest(llu iLimit, llu * pLeft)
{
    if (iCnt > 400000000)
        return 1;

    iCnt++;

    llu iBest = pLast[0] <= iLimit ? pLast[0] : 1;

    auto it = lower_bound(pLeft, pLast, iLimit, greater<llu>());

    while (it < pLast)
    {
        llu iCurrent = *it++;

        llu x = iLimit / iCurrent;

        llu iCandidate = iCurrent * FindTheLargest(x, it);

        if (iCandidate > iBest)
        {
            iBest = iCandidate;
        }
    }

    return iBest;
}


static void Solve()
{
    llu i = FindTheLargest(iN, aPrimes);

    printf("%lld", i);
}


int main(int argc, char * argv[])
{
    ReadData();

    sort(aPrimes, aPrimes + iPrimes, greater<llu>());

    Solve();

	return 0;
}