Problem:
Score : 600 points

Problem Statement

Snuke has a blackboard and a set S consisting of N integers.
The i-th element in S is S_i.

He wrote an integer X on the blackboard, then performed the following operation N times:

Choose one element from S and remove it.

Let x be the number written on the blackboard now, and y be the integer removed from S. Replace the number on the blackboard with x \bmod {y}.

There are N! possible orders in which the elements are removed from S.
For each of them, find the number that would be written on the blackboard after the N operations, and compute the sum of all those N! numbers modulo 10^{9}+7.

Constraints

All values in input are integers.

1 \leq N \leq 200

1 \leq S_i, X \leq 10^{5}

S_i are pairwise distinct.

Input

Input is given from Standard Input in the following format:

N X
S_1 S_2 \ldots S_{N}

Output

Print the answer.

Sample Input 1

2 19
3 7

Sample Output 1

3

There are two possible orders in which we remove the numbers from S.

If we remove 3 and 7 in this order, the number on the blackboard changes as follows: 19 \rightarrow 1 \rightarrow 1.

If we remove 7 and 3 in this order, the number on the blackboard changes as follows: 19 \rightarrow 5 \rightarrow 2.

The output should be the sum of these: 3.

Sample Input 2

5 82
22 11 6 5 13

Sample Output 2

288

Sample Input 3

10 100000
50000 50001 50002 50003 50004 50005 50006 50007 50008 50009

Sample Output 3

279669259

Be sure to compute the sum modulo 10^{9}+7.

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int powmod(int a, int n, int mod) {
	if (n == 0) return 1;
	if (n % 2 == 0) return powmod((a * a) % mod, n / 2, mod);
	return (a * powmod(a, n - 1, mod)) % mod;
}

int mod = 1000000007;
int fact[201];
int factInv[201];

void init() {
	int i;
	fact[0] = 1;
	factInv[0] = 1;
	for (i = 1; i <= 200; i++) {
		fact[i] = (i * fact[i - 1]) % mod;
		factInv[i] = powmod(fact[i], mod - 2, mod);
	}
}

int nPk(int n, int k) {
	if (n < k) return 0;
	return (fact[n] * factInv[n - k]) % mod;
}

int n, x;
int s[200];
int dp[100002];

int getCnt(int l, int r) {
	int x = lower_bound(s, s + n, l) - s;
	int y = lower_bound(s, s + n, r) - s;
	return y - x;
}

int MAX = 100001;
//int MAX = 30;

signed main() {
	int i, j;
	
	init();
	cin >> n >> x;
	rep(i, n) cin >> s[i];
	sort(s, s + n);
	
	dp[MAX] = 1;
	for (i = MAX; i > 0; i--) {
		if (dp[i] == 0) continue;
		//cout << "dp[" << i << "] = " << dp[i] << endl;
		if (i == MAX) {
			int a = getCnt(0, i + 1);
			int b = getCnt(x + 1, i + 1);	//x+1以上i+1未満
			dp[x] += dp[i] * nPk(a, b) % mod;
			dp[x] %= mod;
		}
		else {
			for (j = 0; j < n; j++) {	//Sj
				if (s[j] > i) break;
				//cout << "i, s[j] = " << i << ", " << s[j] << endl;
				int y = i % s[j];
				int a = getCnt(0, i + 1) - 1;
				int b = getCnt(y + 1, i + 1);
				if (s[j] > y) b--;
				//cout << "y, a, b = " << y << ", " << a << ", " << b << endl;
				//cout << "nPk(a, b) = " << nPk(a, b) << endl;
				//cout << endl;
				dp[y] += dp[i] * nPk(a, b) % mod;
				dp[y] %= mod;
			}
		}
	}
	
	int ans = 0;
	for (i = 0; i < s[0]; i++) {
		ans += dp[i] * i;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}