#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using vec = vector<T>;
template <typename K, typename V>
using umap = unordered_map<K, V>;
template <typename K>
using uset = unordered_set<K>;
using vi = vec<int>;
using vl = vec<ll>;
using vpi = vec<pii>;
using vpl = vec<pll>;
using int128 = __int128_t;
using uint128 = __uint128_t;
template <typename I>
string intStr(I x) {
  string ret;
  while (x > 0) {
    ret += (x % 10) + '0';
    x /= 10;
  }
  reverse(ret.begin(), ret.end());
  return ret;
}
template <typename T>
inline void maxa(T& st, T v) {
  st = max(st, v);
}
template <typename T>
inline void mina(T& st, T v) {
  st = min(st, v);
}
inline void setprec(ostream& out, int prec) {
  out << setprecision(prec) << fixed;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> iter) {
  out << "[";
  for (auto t : iter) {
    out << t << ", ";
  }
  out << "]";
  return out;
}
template <typename T>
string arrayStr(T* arr, int sz) {
  string ret = "[";
  for (int i = 0; i < sz; i++) {
    ret += to_string(arr[i]) + ", ";
  }
  return ret + "]";
}
template <typename T>
void printArray(T* arr, int sz) {
  for (int i = 0; i < sz; i++) {
    cout << arr[i] << " ";
  }
  cout << "\n";
}
inline void scan() {}
template <typename F, typename... R>
inline void scan(F& f, R&... r) {
  cin >> f;
  scan(r...);
}
template <typename F>
inline void println(F t) {
  cout << t << '\n';
}
template <typename F, typename... R>
inline void println(F f, R... r) {
  cout << f << " ";
  println(r...);
}
inline void print() {}
template <typename F, typename... R>
inline void print(F f, R... r) {
  cout << f;
  print(r...);
}
vl factor(ll x) {
  ld sqx = sqrt(x) + 100;
  vl ret;
  for (__typeof(1) i = 1; i < sqx + 1; i++) {
    if (x % i == 0) {
      ret.push_back(i);
      ret.push_back(x / i);
    }
  }
  sort(ret.begin(), ret.end());
  ret.resize(unique(ret.begin(), ret.end()) - ret.begin());
  return ret;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
using pll = pair<ll, ll>;
const int MN = 1001, MF = 7001;
int n, par[MN][MF];
pll dp[MN][MF];
ll k;
struct p {
  int i;
  ll v, gv;
  bool operator<(const p& o) const { return v < o.v; }
} num[MN];
vl kfactors;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  scan(n, k);
  kfactors = factor(k);
  int fsz = kfactors.size();
  assert(fsz < MF);
  for (__typeof(1) i = 1; i < n + 1; i++) {
    scan(num[i].v);
    num[i].gv = gcd(num[i].v, k);
    num[i].i = i;
  }
  sort(num + 1, num + n + 1);
  if (k == 1) {
    println(1);
    println(num[1].i);
    return 0;
  }
  pll invalid = make_pair(0x3f3f3f3f3f3f3f3f, 0x3f3f3f3f3f3f3f3f);
  dp[0][0] = {0LL, 0LL};
  for (__typeof(1) i = 1; i < fsz; i++) dp[0][i] = invalid;
  for (__typeof(1) i = 1; i < n + 1; i++) {
    for (__typeof(1) j = 1; j < fsz; j++) {
      dp[i][j] = min(invalid, dp[i - 1][j]);
      par[i][j] = j;
      ll from = kfactors[j] / gcd(num[i].gv, kfactors[j]);
      int fromid = lower_bound((kfactors).begin(), (kfactors).end(), from) -
                   kfactors.begin();
      auto alt = dp[i - 1][fromid];
      alt.first++;
      alt.second += num[i].v;
      if (alt < dp[i][j]) {
        dp[i][j] = alt;
        par[i][j] = fromid;
      }
    }
  }
  if (dp[n][fsz - 1].first == 0x3f3f3f3f3f3f3f3f) {
    println(-1);
    return 0;
  }
  println(dp[n][fsz - 1].first);
  vi seq;
  int ci = n, cj = fsz - 1;
  while (ci > 0 && cj > 0) {
    auto cpar = par[ci][cj];
    if (cj > cpar) seq.push_back(num[ci].i);
    ci--;
    cj = cpar;
  }
  sort(seq.begin(), seq.end());
  for (auto x : seq) print(x, ' ');
  print('\n');
  return 0;
}
