#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 6;
long long cnt[N], arr[N], xx[N];
void solve() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i < n + 1; i++) {
    cin >> arr[i];
    if (arr[i] < N) xx[arr[i]]++;
  }
  for (long long i = 1; i < N; i++) {
    if (xx[i]) {
      long long j = i;
      while (j < N) {
        cnt[j] += xx[i];
        j += i;
      }
    }
  }
  long long mx = -1, idx = -1;
  for (long long i = 1; i < m + 1; i++) {
    if (cnt[i] > mx) {
      idx = i;
      mx = cnt[i];
    }
  }
  cout << idx << " " << mx << "\n";
  for (long long i = 1; i < n + 1; i++)
    if (idx % arr[i] == 0) cout << i << " ";
  cout << "\n";
}
int32_t main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long TestCase = 1;
  while (TestCase--) {
    solve();
  }
  return 0;
}
