#include <bits/stdc++.h>
int n, m, a[100005], t;
long long bit[100005];
std::pair<int, int> sgt2[400005];
void build2(int l, int r, int i) {
  int mid = (l + r) / 2;
  if (l == r) {
    sgt2[i] = std::make_pair(a[mid], mid);
    return;
  }
  build2(l, mid, i * 2);
  build2(mid + 1, r, i * 2 + 1);
  sgt2[i] = std::max(sgt2[i * 2], sgt2[i * 2 + 1]);
}
void update1(int x, int y) {
  y -= a[x];
  for (int i = x; i <= n; i += (i & (-i))) bit[i] += y;
}
void update2(int l, int r, int i, int x, int y) {
  int mid = (l + r) / 2;
  if (l == r) {
    sgt2[i] = std::make_pair(y, mid);
    return;
  }
  if (x <= mid)
    update2(l, mid, i * 2, x, y);
  else
    update2(mid + 1, r, i * 2 + 1, x, y);
  sgt2[i] = std::max(sgt2[i * 2], sgt2[i * 2 + 1]);
}
long long query(int x) {
  long long y = 0;
  for (int i = x; i; i -= (i & (-i))) y += bit[i];
  return y;
}
long long query1(int x, int y) { return query(y) - query(x - 1); }
std::pair<int, int> query2(int l, int r, int i, int x, int y) {
  if (x <= l && r <= y) return sgt2[i];
  std::pair<int, int> z = std::make_pair(0, 0);
  int mid = (l + r) / 2;
  if (l <= x && x <= mid || l <= y && y <= mid || x <= l && mid <= y)
    z = std::max(z, query2(l, mid, i * 2, x, y));
  if (mid + 1 <= x && x <= r || mid + 1 <= y && y <= r ||
      x <= mid + 1 && r <= y)
    z = std::max(z, query2(mid + 1, r, i * 2 + 1, x, y));
  return z;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) update1(i, a[i] + a[i]);
  build2(1, n, 1);
  for (int i = 0; i < m; i++) {
    scanf("%d", &t);
    if (t == 1) {
      int l, r;
      scanf("%d %d", &l, &r);
      printf("%I64d\n", query1(l, r));
    } else if (t == 2) {
      int l, r, x;
      scanf("%d %d %d", &l, &r, &x);
      std::pair<int, int> y = query2(1, n, 1, l, r);
      while (y.first >= x) {
        update1(y.second, y.first % x);
        update2(1, n, 1, y.second, y.first % x);
        a[y.second] = y.first % x;
        y = query2(1, n, 1, l, r);
      }
    } else {
      int k, x;
      scanf("%d %d", &k, &x);
      update1(k, x);
      update2(1, n, 1, k, x);
      a[k] = x;
    }
  }
}
