//後から大きな値で余りを取っても要素の値は変化しない。 //値を降順に並べた列のsubseqだけを試せばOK(ただし最小値は必ず使う) #include #include #include using namespace std; int n, K; int a[20]; signed main() { int i, j; cin >> n >> K; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n, greater()); int ans = 0; for (i = 0; i < (1 << n); i++) { if ((i >> (n - 1)) % 2 == 0) continue; int x = K; for (j = 0; j < n; j++) { if ((i >> j) % 2) { x %= a[j]; } } ans = max(ans, x); } cout << ans << endl; return 0; }