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 #include #include using namespace std; typedef long long ll; int k; ll N; int primes[30]; ll small[960000]; int small_cnt, big_cnt; ll mem[30], mem2[30]; ll tmp, tmp2, res; void cnt(int i) { if(i == min(6, k)) { small[small_cnt++] = tmp2; return ; } mem[i] = tmp, mem2[i] = tmp2; while(tmp >= 1) { if(tmp < primes[i]) { small[small_cnt++] = tmp2; break; } cnt(i + 1); tmp /= ll(primes[i]); tmp2 *= ll(primes[i]); } tmp = mem[i]; tmp2 = mem2[i]; } ll biggest(const ll &n) { int pocz = 0, kon = small_cnt - 1, mid; while(pocz < kon) { mid = (pocz + kon + 1) >> 1; if(small[mid] <= n) pocz = mid; else kon = mid - 1; } return small[pocz]; } void cnt2(int i) { if(i == k) { ll x = biggest(tmp) * tmp2; if(x <= N) res = (res > x) ? res : x; return ; } mem[i] = tmp, mem2[i] = tmp2; while(tmp >= 1) { if(tmp < primes[i]) { ll x = biggest(tmp) * tmp2; if(x <= N) res = (res > x) ? res : x; break; } cnt2(i + 1); tmp /= ll(primes[i]); tmp2 *= ll(primes[i]); } tmp = mem[i]; tmp2 = mem2[i]; } int main() { scanf("%d %lld", &k, &N); for(int i = 0 ; i < k ; i++) scanf("%d", &primes[i]); sort(primes, primes + k); tmp = N, tmp2 = 1; cnt(0); sort(small, small + small_cnt); if(k <= 6) { printf("%lld\n", biggest(N)); return 0; } tmp = N, tmp2 = 1; cnt2(6); printf("%lld\n", res); return 0; }