#include <bits/stdc++.h>
using namespace std;
int n, m, a[1000001], vis[1000001];
vector<int> v[1000001], ans;
int main() {
  cin >> n >> m;
  for (int i = 0, x; i < n; ++i) {
    scanf("%d", &x);
    if (x <= m) {
      v[x].push_back(i + 1);
    }
  }
  int idx = -1, mx = 0;
  for (int i = 1; i <= m; ++i) {
    if (v[i].size()) {
      ++vis[i];
      for (int j = 1; j * i <= m; ++j) {
        a[j * i] += v[i].size();
        ++vis[j * i];
      }
    }
    if (mx < a[i] && vis[i] > 1) {
      mx = a[i];
      idx = i;
    }
  }
  if (idx != -1) {
    printf("%d %d\n", idx, a[idx]);
    for (int j = 1; j * j <= idx; ++j) {
      if (idx % j == 0) {
        for (int k = 0; k < v[j].size(); ++k) {
          ans.push_back(v[j][k]);
        }
        for (int k = 0; k < v[idx / j].size() && idx / j != j; ++k) {
          ans.push_back(v[idx / j][k]);
        }
      }
    }
    sort(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); ++i) {
      printf("%d ", ans[i]);
    }
  } else {
    printf("1 0\n");
  }
  return 0;
}
