#include <bits/stdc++.h>
using namespace std;
unsigned long long n;
int tab[105];
int k;
unsigned long long odp(unsigned long long x, int i){
if(x > n){
return 0;
}
unsigned long long ret = x;
for(int j = i; j <= k; j++){
ret = max( ret, odp(x * tab[j], j) );
}
return ret;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> k >> n;
for(int i = 1; i <= k; i++){
cin >> tab[i];
}
sort(tab + 1, tab + 1 + k);
cout << odp(1, 1) << "\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 | #include <bits/stdc++.h> using namespace std; unsigned long long n; int tab[105]; int k; unsigned long long odp(unsigned long long x, int i){ if(x > n){ return 0; } unsigned long long ret = x; for(int j = i; j <= k; j++){ ret = max( ret, odp(x * tab[j], j) ); } return ret; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> k >> n; for(int i = 1; i <= k; i++){ cin >> tab[i]; } sort(tab + 1, tab + 1 + k); cout << odp(1, 1) << "\n"; } |
English