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

using namespace std;

int main() {

    unsigned long long k;
    unsigned long long N;
    unsigned long long t;

    cin >> k >> N;

    vector<unsigned long long> primes(k);

    for (unsigned long long i=0; i<k; i++) {
        cin >> t;
        primes[i] = t;
    }
    unsigned long long Ncurr = N;
    for(unsigned long long i=N; i>=0; i--) {
        Ncurr = i;
        for (unsigned long long j = 0; j < k; j++) {
            while (Ncurr % primes[j] == 0) {
                Ncurr = Ncurr / primes[j];
            }
        }
        if(Ncurr==1){
            cout << i;
            return 0;
        }

    }

    return 0;
}