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

using namespace std;

int main(int argc, const char * argv[]) {
    long long n, result, tmp;
    int k;
    int primes[100];
    cin >> k >> n;
    if ( k == 1 ) {
        long long prime;
        bool found = false;
        result = tmp = 1;
        cin >> prime;
        while ( !found ) {
            tmp *= prime;
            if ( tmp > n || tmp / prime != result )
                found = true;
            else
                result = tmp;
        }
        cout << result << endl;
    } else {
        for ( int i = 0; i < k; i++ ) {
            cin >> primes[i];
        }
        while ( n > 0 ) {
            long long tmp = n;
            int idx = 0;
            while ( idx < k ) {
                if ( tmp % primes[idx] == 0 ) {
                    tmp /= primes[idx];
                    if ( tmp == 1 ) {
                        cout << n << endl;
                        return 0;
                    }
                } else
                    idx++;
            }
            n--;
        }
        cout << 1 << endl;
    }
    return 0;
}