#include <bits/stdc++.h>
using namespace std;
long long arr[100005];
pair<long long, long long> tree[300005];
long long n, m;
void update(long long i, long long l, long long r, long long pos,
            long long val) {
  if (l == r) {
    tree[i] = {val, val};
    return;
  }
  long long mid = (l + r) / 2;
  if (pos <= mid)
    update(i * 2, l, mid, pos, val);
  else
    update(i * 2 + 1, mid + 1, r, pos, val);
  tree[i] = {tree[i * 2].first + tree[i * 2 + 1].first,
             max(tree[i * 2].second, tree[i * 2 + 1].second)};
}
long long query(long long i, long long l, long long r, long long l1,
                long long r1) {
  if (l1 <= l && r <= r1) return tree[i].first;
  if (r < l1 || l > r1) return 0;
  long long mid = (l + r) / 2;
  return query(i * 2, l, mid, l1, r1) + query(i * 2 + 1, mid + 1, r, l1, r1);
}
void updatemod(long long i, long long l, long long r, long long l1,
               long long r1, long long mod) {
  if (tree[i].second < mod) return;
  if (l == r) {
    tree[i] = {tree[i].first % mod, tree[i].second % mod};
    return;
  }
  long long mid = (l + r) / 2;
  if (r1 <= mid)
    updatemod(i * 2, l, mid, l1, r1, mod);
  else if (l1 > mid)
    updatemod(i * 2 + 1, mid + 1, r, l1, r1, mod);
  else {
    updatemod(i * 2, l, mid, l1, r1, mod);
    updatemod(i * 2 + 1, mid + 1, r, l1, r1, mod);
  }
  tree[i] = {tree[i * 2].first + tree[i * 2 + 1].first,
             max(tree[i * 2].second, tree[i * 2 + 1].second)};
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long m;
  cin >> n >> m;
  long long arr[n + 2];
  for (long long i = 1; i <= n; i++) cin >> arr[i];
  for (long long i = 1; i <= n; i++) update(1, 1, n, i, arr[i]);
  while (m--) {
    long long q;
    cin >> q;
    if (q == 1) {
      long long l, r;
      cin >> l >> r;
      cout << query(1, 1, n, l, r) << '\n';
    } else if (q == 3) {
      long long pos, val;
      cin >> pos >> val;
      arr[pos] = val;
      update(1, 1, n, pos, arr[pos]);
    } else {
      long long l, r, x;
      cin >> l >> r >> x;
      updatemod(1, 1, n, l, r, x);
    }
  }
}
