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
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n;
const long long maks=9223372036854775807;
long long k,x,wynik;
vector<long long>v;
void baktrak(long long w,int poz){
    for(int i=poz;i<v.size();++i){
        if(w>maks/v[i]||w*v[i]>k)continue;
        baktrak(w*v[i],i+1);
    }
    wynik=max(wynik,w);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k;
    for(int i=0;i<n;++i){
        cin>>x;
        v.push_back(x);
        while(x<=1000000000){
            x*=x;
            v.push_back(x);
        }
    }
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();++i){
        if(v[i]>k){
            v.resize(i);
            break;
        }
    }
    reverse(v.begin(),v.end());
    baktrak(1,0);
    cout<<wynik;
}