#include <bits/stdc++.h>
using namespace std;
const int len = 1 << 17;
int n, m, x, y, k;
long long second[300300];
pair<int, int> a[300300];
void upd(int pos, int val) {
  a[pos].first = val;
  second[pos] = val;
  while (pos > 1) {
    pos /= 2;
    if (a[pos * 2].first > a[pos * 2 + 1].first)
      a[pos] = a[pos * 2];
    else
      a[pos] = a[pos * 2 + 1];
    second[pos] = second[pos * 2] + second[pos * 2 + 1];
  }
}
pair<int, int> find_max(int l, int r) {
  pair<int, int> ans;
  ans.first = 0;
  while (l <= r) {
    if (l % 2 == 1 && ans.first < a[l].first) ans = a[l];
    if (r % 2 == 0 && ans.first < a[r].first) ans = a[r];
    l = (l + 1) / 2;
    r = (r - 1) / 2;
  }
  return ans;
}
long long sum(int l, int r) {
  long long res = 0;
  while (l <= r) {
    if (l % 2 == 1) res += second[l];
    if (r % 2 == 0) res += second[r];
    l = (l + 1) / 2;
    r = (r - 1) / 2;
  }
  return res;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    a[len + i].second = i;
    upd(len + i, x);
  }
  for (int i = 0; i < m; ++i) {
    cin >> k;
    if (k == 1) {
      cin >> x >> y;
      cout << sum(x + len - 1, y + len - 1) << endl;
    } else if (k == 2) {
      cin >> x >> y >> k;
      while (true) {
        pair<int, int> mx = find_max(x + len - 1, y + len - 1);
        if (mx.first < k) break;
        upd(mx.second + len, mx.first % k);
      }
    } else {
      cin >> x >> y;
      upd(x + len - 1, y);
    }
  }
  return 0;
}
