#include <bits/stdc++.h>
using namespace std;
int const N = 3312312;
int const INF = 1e9 + 7;
int n, m, a[N];
long long s[N];
pair<int, int> t[N];
void build(int v, int tl, int tr) {
  if (tl == tr) {
    t[v] = {a[tl], tl};
    s[v] = a[tl];
  } else {
    int tm = (tl + tr) >> 1;
    build(v + v, tl, tm);
    build(v + v + 1, tm + 1, tr);
    s[v] = s[v + v] + s[v + v + 1];
    t[v] = max(t[v + v], t[v + v + 1]);
  }
}
long long getsum(int v, int tl, int tr, int l, int r) {
  if (l > r) return 0;
  if (tl == l && r == tr)
    return s[v];
  else {
    int tm = (tl + tr) >> 1;
    return getsum(v + v, tl, tm, l, min(r, tm)) +
           getsum(v + v + 1, tm + 1, tr, max(l, tm + 1), r);
  }
}
pair<int, int> getmax(int v, int tl, int tr, int l, int r) {
  if (l > r) return {-1, -1};
  if (tl == l && tr == r)
    return t[v];
  else {
    int tm = (tl + tr) >> 1;
    return max(getmax(v + v, tl, tm, l, min(r, tm)),
               getmax(v + v + 1, tm + 1, tr, max(l, tm + 1), r));
  }
}
void update(int v, int tl, int tr, int pos, int val) {
  if (tl == tr) {
    s[v] = val;
    t[v] = {val, tl};
  } else {
    int tm = (tl + tr) >> 1;
    if (pos <= tm)
      update(v + v, tl, tm, pos, val);
    else
      update(v + v + 1, tm + 1, tr, pos, val);
    t[v] = max(t[v + v], t[v + v + 1]);
    s[v] = s[v + v] + s[v + v + 1];
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int c = 1; c <= n; c++) {
    scanf("%d", &a[c]);
  }
  build(1, 1, n);
  pair<int, int> x = getmax(1, 1, n, 1, n);
  for (int c = 1; c <= m; c++) {
    int type, l, r, x, pos;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d %d", &l, &r);
      printf("%I64d\n", getsum(1, 1, n, l, r));
    } else if (type == 2) {
      scanf("%d %d %d", &l, &r, &x);
      while (1) {
        pair<int, int> cur = getmax(1, 1, n, l, r);
        if (cur.first >= x) {
          update(1, 1, n, cur.second, cur.first % x);
        } else
          break;
      }
    } else {
      scanf("%d %d", &pos, &x);
      update(1, 1, n, pos, x);
    }
  }
  return 0;
}
