/* -*- coding: utf-8 -*- * * 1083.cc: No.1083 余りの余り - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 20; const int NBITS = 1 << MAX_N; /* typedef */ /* global variables */ int as[MAX_N], dp[NBITS]; /* subroutines */ inline void setmax(int &a, int b) { if (a < b) a = b; } /* main */ int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", as + i); int nbits = 1 << n; dp[0] = k; for (int bits = 0; bits < nbits; bits++) for (int i = 0, bi = 1; i < n; i++, bi <<= 1) if (! (bits & bi)) setmax(dp[bits | bi], dp[bits] % as[i]); printf("%d\n", dp[nbits - 1]); return 0; }