#include <bits/stdc++.h>
using namespace std;
struct nd {
  int mx, ind;
  long long sum;
};
int n, m, a[100005], t, p1, p2, p3;
nd seg[270000];
void build(int l, int r, int cur) {
  if (l == r) {
    seg[cur] = {a[l], l, a[l]};
    return;
  }
  build(l, (l + r) / 2, 2 * cur + 1);
  build((l + r) / 2 + 1, r, 2 * cur + 2);
  seg[cur].mx = max(seg[2 * cur + 1].mx, seg[2 * cur + 2].mx);
  seg[cur].sum = seg[2 * cur + 1].sum + seg[2 * cur + 2].sum;
  if (seg[2 * cur + 1].mx >= seg[2 * cur + 2].mx)
    seg[cur].ind = seg[2 * cur + 1].ind;
  else
    seg[cur].ind = seg[2 * cur + 2].ind;
}
void upd(int l, int r, int targ, int cur, int val) {
  if (r < targ or targ < l) return;
  if (l == r) {
    seg[cur] = {val, l, val};
    return;
  }
  upd(l, (l + r) / 2, targ, 2 * cur + 1, val);
  upd((l + r) / 2 + 1, r, targ, 2 * cur + 2, val);
  seg[cur].mx = max(seg[2 * cur + 1].mx, seg[2 * cur + 2].mx);
  seg[cur].sum = seg[2 * cur + 1].sum + seg[2 * cur + 2].sum;
  if (seg[2 * cur + 1].mx >= seg[2 * cur + 2].mx)
    seg[cur].ind = seg[2 * cur + 1].ind;
  else
    seg[cur].ind = seg[2 * cur + 2].ind;
}
long long que(int l, int r, int tl, int tr, int cur) {
  if (r < tl or tr < l) return 0;
  if (tl <= l and r <= tr) return seg[cur].sum;
  return que(l, (l + r) / 2, tl, tr, 2 * cur + 1) +
         que((l + r) / 2 + 1, r, tl, tr, 2 * cur + 2);
}
int getmax(int l, int r, int tl, int tr, int cur) {
  if (r < tl or tr < l) return 0;
  if (tl <= l and r <= tr) return seg[cur].ind;
  int i1 = getmax(l, (l + r) / 2, tl, tr, 2 * cur + 1),
      i2 = getmax((l + r) / 2 + 1, r, tl, tr, 2 * cur + 2);
  if (a[i1] > a[i2])
    return i1;
  else
    return i2;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  build(0, n, 0);
  for (int i = 0; i < m; i++) {
    cin >> t;
    if (t == 1) {
      cin >> p1 >> p2;
      cout << que(0, n, p1, p2, 0) << '\n';
    } else if (t == 2) {
      cin >> p1 >> p2 >> p3;
      int ind = getmax(0, n, p1, p2, 0);
      while (a[ind] >= p3) {
        upd(0, n, ind, 0, a[ind] % p3);
        a[ind] %= p3;
        ind = getmax(0, n, p1, p2, 0);
      }
    } else {
      cin >> p1 >> p2;
      upd(0, n, p1, 0, p2);
      a[p1] = p2;
    }
  }
}
