#undef _GLIBCXX_DEBUG //#pragma GCC optimize("O3") #include<iostream> #include<algorithm> #include<vector> #define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++) #define all(v) (v).begin(), (v).end() #define SZ(v) (int)((v).size()) #define pb push_back #define ft first #define sd second typedef long long ll; typedef unsigned long long ull; typedef long double ld; const long long INF = 4e18L + 1; const int IINF = 2e9 + 1; using namespace std; template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; } template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...); } #ifdef LOCAL #define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #else #define DBG(...) (__VA_ARGS__) #define cerr if(0)cout #endif const int maxtab = 1500000; ll k, N; ll sqrtN; ll tab[25]; ll T[25]; ll kand = 1; int tryb; ll maxrek = 0; int pom[maxtab]; int ile_mam_w_tab; int ktory_dod; int wez_ind(ll moj_max) { if (pom[0] > moj_max) return -1; int ok = 0, nieok = ile_mam_w_tab; while(nieok - ok > 1) { int sr = (ok + nieok)/2; if (pom[sr] <= moj_max) ok = sr; else nieok = sr; } return ok; } inline void dodaj(ll co, ll pr) { if (tryb == 2 || tryb == 4) { if (co <= N) kand = max(kand, co); if (co > T[pr]*sqrtN || ile_mam_w_tab == 0) return; ll moj_maks = N/co; //int ind = wez_ind(moj_maks); int ind = upper_bound(pom, pom+ile_mam_w_tab, moj_maks) - pom - 1; if (ind >= 0) { kand = max(kand, pom[ind] * co); } return; } if (co*100ll < sqrtN) return; if (ktory_dod < maxtab && tryb == 1) { pom[ktory_dod] = co; ile_mam_w_tab++; } if (ktory_dod >= maxtab && tryb == 3) { pom[ktory_dod-maxtab] = co; ile_mam_w_tab++; } ktory_dod++; } void rek(ll akt_wyn, int ind, int pr = -1) { if (ind == k) return; bool pier = true; while(akt_wyn <= maxrek) { if (!pier) dodaj(akt_wyn, pr); pier = false; rek(akt_wyn, ind+1, pr); if (pr == -1) pr = ind; akt_wyn *= tab[ind]; } } void rob(int t) { tryb = t; if (t == 2 || t == 4) { maxrek = 10*sqrtN; rek(1, 0); } else { maxrek = sqrtN; ile_mam_w_tab = 0; ktory_dod = 0; rek(1, 0); sort(pom, pom + ile_mam_w_tab); } } int main() { #ifndef LOCAL ios_base::sync_with_stdio(0); cin.tie(0); #endif cin>>k>>N; for(int i=0; i<k; i++) { cin>>tab[i]; T[i] = ceil(sqrt((double)tab[i])); } sort(tab, tab+k); sort(T, T+k); sqrtN = 0; ll skok = 10000; while( (sqrtN + skok) * (sqrtN + skok) <= N) sqrtN += skok; skok = 1; while( (sqrtN + skok) * (sqrtN + skok) <= N) sqrtN += skok; rob(1); rob(2); rob(3); rob(4); cout << kand; 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | #undef _GLIBCXX_DEBUG //#pragma GCC optimize("O3") #include<iostream> #include<algorithm> #include<vector> #define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++) #define all(v) (v).begin(), (v).end() #define SZ(v) (int)((v).size()) #define pb push_back #define ft first #define sd second typedef long long ll; typedef unsigned long long ull; typedef long double ld; const long long INF = 4e18L + 1; const int IINF = 2e9 + 1; using namespace std; template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; } template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...); } #ifdef LOCAL #define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #else #define DBG(...) (__VA_ARGS__) #define cerr if(0)cout #endif const int maxtab = 1500000; ll k, N; ll sqrtN; ll tab[25]; ll T[25]; ll kand = 1; int tryb; ll maxrek = 0; int pom[maxtab]; int ile_mam_w_tab; int ktory_dod; int wez_ind(ll moj_max) { if (pom[0] > moj_max) return -1; int ok = 0, nieok = ile_mam_w_tab; while(nieok - ok > 1) { int sr = (ok + nieok)/2; if (pom[sr] <= moj_max) ok = sr; else nieok = sr; } return ok; } inline void dodaj(ll co, ll pr) { if (tryb == 2 || tryb == 4) { if (co <= N) kand = max(kand, co); if (co > T[pr]*sqrtN || ile_mam_w_tab == 0) return; ll moj_maks = N/co; //int ind = wez_ind(moj_maks); int ind = upper_bound(pom, pom+ile_mam_w_tab, moj_maks) - pom - 1; if (ind >= 0) { kand = max(kand, pom[ind] * co); } return; } if (co*100ll < sqrtN) return; if (ktory_dod < maxtab && tryb == 1) { pom[ktory_dod] = co; ile_mam_w_tab++; } if (ktory_dod >= maxtab && tryb == 3) { pom[ktory_dod-maxtab] = co; ile_mam_w_tab++; } ktory_dod++; } void rek(ll akt_wyn, int ind, int pr = -1) { if (ind == k) return; bool pier = true; while(akt_wyn <= maxrek) { if (!pier) dodaj(akt_wyn, pr); pier = false; rek(akt_wyn, ind+1, pr); if (pr == -1) pr = ind; akt_wyn *= tab[ind]; } } void rob(int t) { tryb = t; if (t == 2 || t == 4) { maxrek = 10*sqrtN; rek(1, 0); } else { maxrek = sqrtN; ile_mam_w_tab = 0; ktory_dod = 0; rek(1, 0); sort(pom, pom + ile_mam_w_tab); } } int main() { #ifndef LOCAL ios_base::sync_with_stdio(0); cin.tie(0); #endif cin>>k>>N; for(int i=0; i<k; i++) { cin>>tab[i]; T[i] = ceil(sqrt((double)tab[i])); } sort(tab, tab+k); sort(T, T+k); sqrtN = 0; ll skok = 10000; while( (sqrtN + skok) * (sqrtN + skok) <= N) sqrtN += skok; skok = 1; while( (sqrtN + skok) * (sqrtN + skok) <= N) sqrtN += skok; rob(1); rob(2); rob(3); rob(4); cout << kand; return 0; } |