#include <bits/stdc++.h>
using namespace std;
const int MAXn = 1e5 + 10, MAXx = 4 * MAXn;
struct salar {
  int l, r, max1, leftchild, rightchild, id;
  long long sum;
  salar() { sum = id = l = r = max1 = leftchild = rightchild = 0; }
  void idit(int v) {
    id = v;
    leftchild = 2 * v;
    rightchild = 2 * v + 1;
  }
};
salar seg[MAXx];
int ar[MAXn], n, m;
void build(int v, int l, int r) {
  seg[v].l = l, seg[v].r = r;
  seg[v].idit(v);
  if (r - l == 1) {
    seg[v].sum = ar[l];
    seg[v].max1 = ar[l];
    return;
  }
  int med = (l + r) / 2;
  build(seg[v].leftchild, l, med);
  build(seg[v].rightchild, med, r);
  seg[v].sum = seg[seg[v].leftchild].sum + seg[seg[v].rightchild].sum;
  seg[v].max1 = max(seg[seg[v].leftchild].max1, seg[seg[v].rightchild].max1);
}
long long get(int v, int l, int r) {
  if (max(l, seg[v].l) >= min(r, seg[v].r)) return 0;
  if (l <= seg[v].l && seg[v].r <= r) {
    return seg[v].sum;
  }
  return get(seg[v].leftchild, l, r) + get(seg[v].rightchild, l, r);
}
void domodule(int v, int l, int r, int x) {
  if (seg[v].max1 < x) return;
  if (max(l, seg[v].l) >= min(r, seg[v].r)) return;
  if (seg[v].r - seg[v].l == 1) {
    ar[seg[v].l] %= x;
    seg[v].sum = ar[seg[v].l];
    seg[v].max1 = ar[seg[v].l];
    return;
  }
  domodule(seg[v].leftchild, l, r, x);
  domodule(seg[v].rightchild, l, r, x);
  seg[v].sum = seg[seg[v].leftchild].sum + seg[seg[v].rightchild].sum;
  seg[v].max1 = max(seg[seg[v].leftchild].max1, seg[seg[v].rightchild].max1);
}
void change(int v, int l, int x) {
  if (l < seg[v].l || l >= seg[v].r) return;
  if (seg[v].r - seg[v].l == 1) {
    ar[seg[v].l] = x;
    seg[v].sum = ar[seg[v].l];
    seg[v].max1 = ar[seg[v].l];
    return;
  }
  change(seg[v].leftchild, l, x);
  change(seg[v].rightchild, l, x);
  seg[v].sum = seg[seg[v].leftchild].sum + seg[seg[v].rightchild].sum;
  seg[v].max1 = max(seg[seg[v].leftchild].max1, seg[seg[v].rightchild].max1);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> ar[i];
  build(1, 0, n);
  for (int i = 0; i < m; i++) {
    int type;
    cin >> type;
    if (type == 1) {
      int l, r;
      cin >> l >> r;
      l--;
      cout << get(1, l, r) << endl;
    } else if (type == 2) {
      int l, r, x;
      cin >> l >> r >> x;
      l--;
      domodule(1, l, r, x);
    } else {
      int l, x;
      cin >> l >> x;
      l--;
      change(1, l, x);
    }
  }
}
