#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
struct Node {
  long long mx, sum, idmx;
  void mergee(Node a, Node b) {
    mx = max(a.mx, b.mx);
    sum = a.sum + b.sum;
    if (a.mx >= b.mx)
      idmx = a.idmx;
    else
      idmx = b.idmx;
  }
} ST[4 * N];
long long n, m, a[N];
void update(int id, int l, int r, int i, int v) {
  if (i < l || i > r) return;
  if (r == l) {
    ST[id].mx = ST[id].sum = v;
    ST[id].idmx = i;
    a[i] = v;
    return;
  }
  int mid = l + r >> 1;
  update(id * 2, l, mid, i, v);
  update(id * 2 + 1, mid + 1, r, i, v);
  ST[id].mergee(ST[id * 2], ST[id * 2 + 1]);
}
Node get(int id, int l, int r, int u, int v) {
  Node res = {0, 0, 0};
  if (r < u || l > v) return res;
  if (u <= l && r <= v) return ST[id];
  int mid = l + r >> 1;
  res.mergee(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
  return res;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) update(1, 1, n, i, a[i]);
  while (m--) {
    int type, l, r, x, k;
    cin >> type;
    if (type == 1) {
      cin >> l >> r;
      cout << get(1, 1, n, l, r).sum << endl;
    } else if (type == 2) {
      cin >> l >> r >> x;
      while (get(1, 1, n, l, r).mx >= x)
        update(1, 1, n, get(1, 1, n, l, r).idmx,
               a[get(1, 1, n, l, r).idmx] % x);
    } else
      cin >> k >> x, update(1, 1, n, k, x);
  }
}
