#include<iostream> #include<cstdlib> #include<cstdio> #define mid ((l + r) >> 1) usingnamespacestd; inlineintread() { int f = 1, x = 0; char ch;
do{ ch = getchar(); if (ch == '-') f = -1; }while(ch < '0' || ch > '9'); do{ x = x * 10 + ch - '0'; ch = getchar(); }while(ch >= '0' && ch <= '9'); return f * x; } constint N = 18; constint MAXX = 5.4e6;
int n, k; int a[N + 1]; int type[MAXX + 1], w[1 << N]; int ans;
inlinevoidinit() { for (int i = 1; i <= MAXX; i++) { int sum = 0; for (int j = 1; j <= n; j++) if (i % (2 * a[j]) > 0 && i % (2 * a[j]) <= a[j]) sum |= (1 << (j - 1)); type[i] = sum; } return; } inlineboolcheck(int val) { int sum, flow = n * k, p = n * k + val;
for (int S = 0; S < 1 << n; S++) w[S] = 0; for (int i = 1; i <= val; i++) w[type[i]]++; for (int i = 1; i <= n; i++) { for (int S = 0; S < 1 << n; S++) if (S & (1 << (i - 1))) w[S] += w[S ^ (1 << (i - 1))]; } for (int S = 0; S < 1 << n; S++) { sum = p - w[S]; for (int i = 1; i <= n; i++) if ((S & (1 << (i - 1))) == 0) sum -= k; flow = min(flow, sum); } return flow >= n * k; } intmain() { n = read(); k = read(); for (int i = 1; i <= n; i++) a[i] = read(); init();
int l = n * k, r = MAXX;
while (l <= r) { if (check(mid)) { ans = mid; r = mid - 1; } else { l = mid + 1; } }