#include <bits/stdc++.h>
using namespace std;
ifstream fin("in.in");
ofstream fout("out.out");
const int N = 1e5 + 10;
int n, m, a[N];
pair<long long, int> node[(N << 2) + 10];
long long getSum(int s, int e, int tag, int l, int r) {
  if (l >= r || s >= r || e <= l) return 0;
  if (s >= l && e <= r) return node[tag].first;
  int mid = (s + e) >> 1;
  return getSum(s, mid, tag * 2, l, r) + getSum(mid, e, tag * 2 + 1, l, r);
}
int getMax(int s, int e, int tag, int l, int r) {
  if (l >= r || s >= r || e <= l) return n;
  if (s >= l && e <= r) return node[tag].second;
  int mid = (s + e) >> 1;
  int mx1 = getMax(s, mid, tag * 2, l, r),
      mx2 = getMax(mid, e, tag * 2 + 1, l, r);
  if (a[mx1] > a[mx2]) return mx1;
  return mx2;
}
void update(int s, int e, int tag, int pos) {
  if (s + 1 == e) {
    node[tag].first = a[pos];
    return;
  }
  int mid = (s + e) >> 1;
  if (pos < mid)
    update(s, mid, tag * 2, pos);
  else
    update(mid, e, tag * 2 + 1, pos);
  node[tag].first = node[tag * 2].first + node[tag * 2 + 1].first;
  if (a[node[tag * 2].second] > a[node[tag * 2 + 1].second])
    node[tag].second = node[tag * 2].second;
  else
    node[tag].second = node[tag * 2 + 1].second;
}
void buildTree(int s, int e, int tag) {
  if (s + 1 == e) {
    node[tag].first = a[s];
    node[tag].second = s;
    return;
  }
  int mid = (s + e) >> 1;
  buildTree(s, mid, tag * 2);
  buildTree(mid, e, tag * 2 + 1);
  node[tag].first = node[tag * 2].first + node[tag * 2 + 1].first;
  if (a[node[tag * 2].second] > a[node[tag * 2 + 1].second])
    node[tag].second = node[tag * 2].second;
  else
    node[tag].second = node[tag * 2 + 1].second;
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  buildTree(0, n, 1);
  while (m) {
    int t;
    cin >> t;
    if (t == 1) {
      int l, r;
      cin >> l >> r;
      cout << getSum(0, n, 1, l - 1, r) << endl;
      m--;
      continue;
    }
    if (t == 3) {
      int k, x;
      cin >> k >> x;
      a[--k] = x;
      update(0, n, 1, k);
      m--;
      continue;
    }
    int l, r, x;
    cin >> l >> r >> x;
    int k = getMax(0, n, 1, --l, r);
    while (a[k] >= x) {
      a[k] %= x;
      update(0, n, 1, k);
      k = getMax(0, n, 1, l, r);
    }
    m--;
  }
  return 0;
}
