#include<bits/stdc++.h>
using namespace std;
int p[105];
long long int N,k,maks=0;
long long int wynik=1;
void reku(){
for(int i=0;i<k;i++){
if(wynik*p[i]<=N){
wynik*=p[i];
if(wynik>maks)
maks=wynik;
reku();
wynik/=p[i];
}
else
return;
}
}
int main(){
cin >> k >> N;
for(int i=0;i<k;i++){
cin >> p[i];
}
sort(p,p+k);
reku();
cout << maks;
}
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 | #include<bits/stdc++.h> using namespace std; int p[105]; long long int N,k,maks=0; long long int wynik=1; void reku(){ for(int i=0;i<k;i++){ if(wynik*p[i]<=N){ wynik*=p[i]; if(wynik>maks) maks=wynik; reku(); wynik/=p[i]; } else return; } } int main(){ cin >> k >> N; for(int i=0;i<k;i++){ cin >> p[i]; } sort(p,p+k); reku(); cout << maks; } |
English