#include <bits/stdc++.h>
using namespace std;
long long int primes[10], arr[100050][10], Segtree[270000][10],
    lazy[270000][10], segsiz, n, k, cnt;
vector<int> prms;
void genprimes() {
  for (int i = 2; i < 2000; i++) {
    bool prm = true;
    for (int prim : prms) {
      if (i % prim == 0) {
        prm = false;
        break;
      }
    }
    if (prm) {
      prms.push_back(i);
    }
  }
}
void build() {
  segsiz = 1;
  while (segsiz < n) {
    segsiz *= 2;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < cnt; j++) {
      Segtree[i + segsiz][j] = arr[i][j];
    }
  }
  for (int i = segsiz - 1; i >= 1; i--) {
    for (int j = 0; j < cnt; j++) {
      Segtree[i][j] = Segtree[i * 2][j] + Segtree[i * 2 + 1][j];
    }
  }
}
long long int upd[10];
void update(int node, int start, int end, int l, int r) {
  for (int i = 0; i < cnt; i++) {
    if (lazy[node][i] > 0) {
      Segtree[node][i] += lazy[node][i] * (end - start + 1);
      if (start != end) {
        lazy[node * 2][i] += lazy[node][i];
        lazy[node * 2 + 1][i] += lazy[node][i];
      }
      lazy[node][i] = 0;
    }
  }
  if (end < start || start > r || end < l) {
    return;
  }
  if (start >= l && end <= r) {
    for (int i = 0; i < cnt; i++) {
      lazy[node][i] += upd[i];
    }
    return;
  }
  for (int i = 0; i < cnt; i++) {
    Segtree[node][i] += upd[i] * (min(end, r) - max(l, start) + 1);
  }
  int mid = (start + end) / 2;
  update(node * 2, start, mid, l, r);
  update(node * 2 + 1, mid + 1, end, l, r);
}
long long int answs[10];
void query(int node, int start, int end, int l, int r) {
  for (int i = 0; i < cnt; i++) {
    if (lazy[node][i] > 0) {
      Segtree[node][i] += lazy[node][i] * (end - start + 1);
      if (start != end) {
        lazy[node * 2][i] += lazy[node][i];
        lazy[node * 2 + 1][i] += lazy[node][i];
      }
      lazy[node][i] = 0;
    }
  }
  if (end < start || start > r || end < l) {
    return;
  }
  if (start >= l && end <= r) {
    for (int i = 0; i < cnt; i++) {
      answs[i] += Segtree[node][i];
    }
    return;
  }
  int mid = (start + end) / 2;
  query(node * 2, start, mid, l, r);
  query(node * 2 + 1, mid + 1, end, l, r);
}
int primecnts[10];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> n >> k >> q;
  genprimes();
  cnt = 0;
  for (unsigned int i = 0; i < prms.size(); i++) {
    if (k % prms[i] == 0) {
      primes[cnt++] = prms[i];
      while (k % prms[i] == 0) {
        k /= prms[i];
        primecnts[cnt - 1]++;
      }
    }
  }
  if (k > 1) {
    primes[cnt++] = k;
    primecnts[cnt - 1] = 1;
  }
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    for (int j = 0; j < cnt; j++) {
      while (x % primes[j] == 0) {
        arr[i][j]++;
        x /= primes[j];
      }
    }
  }
  build();
  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      int l, r, v;
      cin >> l >> r >> v;
      memset(upd, 0, sizeof(upd));
      for (int j = 0; j < cnt; j++) {
        while (v % primes[j] == 0) {
          upd[j]++;
          v /= primes[j];
        }
      }
      update(1, segsiz, 2 * segsiz - 1, l + segsiz - 1, r + segsiz - 1);
    } else {
      int l, r;
      cin >> l >> r;
      memset(answs, 0, sizeof(answs));
      query(1, segsiz, 2 * segsiz - 1, l + segsiz - 1, r + segsiz - 1);
      long long int ans = 9223372036854775807LL;
      for (int j = 0; j < cnt; j++) {
        ans = min(ans, answs[j] / primecnts[j]);
      }
      cout << ans << "\n" << flush;
    }
  }
  return 0;
}
