#include <bits/stdc++.h>
using namespace std;
const int maxn = 111111;
int a[maxn];
struct Tree {
  Tree *pl, *pr;
  int l, r;
  int mx;
  long long sum;
  Tree() {}
  ~Tree() {
    if (pl) pl->~Tree();
    if (pr) pr->~Tree();
    delete this;
  }
  void update() {
    sum = pl->sum + pr->sum;
    mx = max(pl->mx, pr->mx);
  }
  Tree(int l, int r) : l(l), r(r) {
    if (l == r) {
      sum = mx = a[l];
      return;
    }
    int m = (l + r) >> 1;
    pl = new Tree(l, m);
    pr = new Tree(m + 1, r);
    update();
  }
  long long query(int L, int R) {
    if (L <= l && r <= R) return sum;
    int m = (l + r) >> 1;
    long long ans = 0;
    if (L <= m) ans += pl->query(L, R);
    if (R > m) ans += pr->query(L, R);
    return ans;
  }
  void modulo(int L, int R, int x) {
    if (mx < x) return;
    if (l == r) {
      sum %= x;
      mx %= x;
      return;
    }
    int m = (l + r) >> 1;
    if (L <= m) pl->modulo(L, R, x);
    if (R > m) pr->modulo(L, R, x);
    update();
  }
  void set(int k, int x) {
    if (l == r) {
      sum = x;
      mx = x;
      return;
    }
    int m = (l + r) >> 1;
    if (k <= m)
      pl->set(k, x);
    else
      pr->set(k, x);
    update();
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  while (cin >> n >> m) {
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    Tree* lx = new Tree(1, n);
    int ty, l, r, k, x;
    for (int i = 0; i < m; i++) {
      cin >> ty;
      if (ty == 1) {
        cin >> l >> r;
        cout << lx->query(l, r) << endl;
      } else if (ty == 2) {
        cin >> l >> r >> x;
        lx->modulo(l, r, x);
      } else {
        cin >> k >> x;
        lx->set(k, x);
      }
    }
  }
  return 0;
}
