#include<bits/stdc++.h>
using namespace std;
vector<int> pr;
long long n,k,a,mx = 0;
void calc(long long x, vector<int>::iterator it)
{
if(k/(*it) < x) {
return;
}
x*=*it;
if(x>k) {
return;
}
mx = max(mx, x);
while(it!=pr.end()) {
calc(x, it);
it++;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin>>n>>k;
for(int i = 0;i<n;i++) {
cin>>a;
pr.push_back(a);
}
for(auto it = pr.begin();it != pr.end();it++) {
calc(1,it);
}
cout<<mx<<"\n";
}
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<bits/stdc++.h> using namespace std; vector<int> pr; long long n,k,a,mx = 0; void calc(long long x, vector<int>::iterator it) { if(k/(*it) < x) { return; } x*=*it; if(x>k) { return; } mx = max(mx, x); while(it!=pr.end()) { calc(x, it); it++; } } int main() { ios_base::sync_with_stdio(0); cin>>n>>k; for(int i = 0;i<n;i++) { cin>>a; pr.push_back(a); } for(auto it = pr.begin();it != pr.end();it++) { calc(1,it); } cout<<mx<<"\n"; } |
English