#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <set> #include <vector> #include <queue> #include <stack> #include <map> #include <cmath> #include <bitset> #include <fstream> using namespace std; #define pi pair<int,int> #define mp(x,y) make_pair(x,y) #define fi first #define se second #define pl pair<long long,long long> #define pb push_back #define vi vector<int> #define ll long long const int MAXN=250001, mod=1e9+7; const ll inf=1000000000000000000LL; ll n,naj; int pie[105],k; vector<ll> v; void wal1(int nr, ll co) { if (nr>=k || nr==5) { v.pb(co); return; } wal1(nr+1,co); for (ll x=co; x<=n/pie[nr]; x*=pie[nr]) wal1(nr+1,x*pie[nr]); } void wal2(int nr, ll co) { if (nr>=k) { int i=upper_bound(v.begin(),v.end(),n/co)-v.begin(); i--; naj=max(naj,co*v[i]); return; } wal2(nr+1,co); for (ll x=co; x<=n/pie[nr]; x*=pie[nr]) wal2(nr+1,x*pie[nr]); } int main () { int a,b,c; scanf("%d%lld", &k, &n); for (a=0; a<k; a++) scanf("%d", &pie[a]); sort(pie,pie+k); wal1(0,1); sort(v.begin(),v.end()); naj=*v.rbegin(); wal2(5,1); printf("%lld", naj); return 0; }
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <set> #include <vector> #include <queue> #include <stack> #include <map> #include <cmath> #include <bitset> #include <fstream> using namespace std; #define pi pair<int,int> #define mp(x,y) make_pair(x,y) #define fi first #define se second #define pl pair<long long,long long> #define pb push_back #define vi vector<int> #define ll long long const int MAXN=250001, mod=1e9+7; const ll inf=1000000000000000000LL; ll n,naj; int pie[105],k; vector<ll> v; void wal1(int nr, ll co) { if (nr>=k || nr==5) { v.pb(co); return; } wal1(nr+1,co); for (ll x=co; x<=n/pie[nr]; x*=pie[nr]) wal1(nr+1,x*pie[nr]); } void wal2(int nr, ll co) { if (nr>=k) { int i=upper_bound(v.begin(),v.end(),n/co)-v.begin(); i--; naj=max(naj,co*v[i]); return; } wal2(nr+1,co); for (ll x=co; x<=n/pie[nr]; x*=pie[nr]) wal2(nr+1,x*pie[nr]); } int main () { int a,b,c; scanf("%d%lld", &k, &n); for (a=0; a<k; a++) scanf("%d", &pie[a]); sort(pie,pie+k); wal1(0,1); sort(v.begin(),v.end()); naj=*v.rbegin(); wal2(5,1); printf("%lld", naj); return 0; } |