#include <bits/stdc++.h>
using namespace std;
const int N = 121111;
int num[N];
struct SegTree {
  int stl[4 * N], str[4 * N];
  long long stsum[4 * N];
  int stmax[4 * N];
  inline SegTree() {}
  inline void build(int left, int right, int x = 1) {
    stl[x] = left;
    str[x] = right;
    if (left + 1 == right) {
      stmax[x] = left;
      stsum[x] = num[left];
    } else {
      int mid = (left + right) >> 1;
      build(left, mid, 2 * x);
      build(mid, right, 2 * x + 1);
      stsum[x] = stsum[2 * x] + stsum[2 * x + 1];
      stmax[x] = num[stmax[2 * x]] > num[stmax[2 * x + 1]] ? stmax[2 * x]
                                                           : stmax[2 * x + 1];
    }
  }
  inline long long qsum(int left, int right, int x = 1) {
    if (left == stl[x] && right == str[x]) return stsum[x];
    int mid = (stl[x] + str[x]) >> 1;
    if (right <= mid)
      return qsum(left, right, 2 * x);
    else if (left >= mid)
      return qsum(left, right, 2 * x + 1);
    else
      return qsum(left, mid, 2 * x) + qsum(mid, right, 2 * x + 1);
  }
  inline int qmax(int left, int right, int x = 1) {
    if (left == stl[x] && right == str[x]) return stmax[x];
    int mid = (stl[x] + str[x]) >> 1;
    if (right <= mid)
      return qmax(left, right, 2 * x);
    else if (left >= mid)
      return qmax(left, right, 2 * x + 1);
    else {
      int ql = qmax(left, mid, 2 * x);
      int qr = qmax(mid, right, 2 * x + 1);
      if (num[ql] > num[qr])
        return ql;
      else
        return qr;
    }
  }
  inline void update(int pos, int x = 1) {
    if (stl[x] + 1 == str[x])
      stsum[x] = num[pos];
    else {
      int mid = (stl[x] + str[x]) >> 1;
      if (pos < mid)
        update(pos, 2 * x);
      else
        update(pos, 2 * x + 1);
      stsum[x] = stsum[2 * x] + stsum[2 * x + 1];
      stmax[x] = num[stmax[2 * x]] > num[stmax[2 * x + 1]] ? stmax[2 * x]
                                                           : stmax[2 * x + 1];
    }
  }
} A;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> num[i];
  A.build(1, n + 1);
  while (m--) {
    int type;
    cin >> type;
    if (type == 1) {
      int l, r;
      cin >> l >> r;
      cout << A.qsum(l, r + 1) << '\n';
    } else if (type == 2) {
      int l, r, x;
      cin >> l >> r >> x;
      bool flag = false;
      do {
        flag = false;
        int t = A.qmax(l, r + 1);
        if (num[t] >= x) flag = true;
        num[t] %= x;
        A.update(t);
      } while (flag);
    } else {
      int k, x;
      cin >> k >> x;
      num[k] = x;
      A.update(k);
    }
  }
  return 0;
}
