#include <bits/stdc++.h>
using namespace std;
long long t = 1;
const long long N = 2e5 + 44;
long long segTree[4 * N], segTree2[4 * N], A[N];
inline long long merge(long long x, long long y) { return x + y; }
inline long long merge2(long long x, long long y) {
  return A[x] > A[y] ? x : y;
}
void update(long long node, long long l, long long r, long long idx,
            long long val) {
  if (l == r) {
    segTree[node] = val;
    segTree2[node] = l;
    A[idx] = val;
    return;
  }
  long long mid = (l + r) / 2;
  if (l <= idx and idx <= mid)
    update(node << 1, l, mid, idx, val);
  else
    update(node << 1 | 1, mid + 1, r, idx, val);
  segTree[node] = merge(segTree[node << 1], segTree[node << 1 | 1]);
  segTree2[node] = merge2(segTree2[node << 1], segTree2[node << 1 | 1]);
}
long long querySum(long long node, long long l, long long r, long long a,
                   long long b) {
  if (l > b || r < a || l > r) return 0;
  if (a <= l and r <= b) return segTree[node];
  long long mid = (l + r) / 2;
  return merge(querySum(node << 1, l, mid, a, b),
               querySum(node << 1 | 1, mid + 1, r, a, b));
}
long long queryMax(long long node, long long l, long long r, long long a,
                   long long b) {
  if (l > b || r < a || l > r) return 0;
  if (a <= l and r <= b) return segTree2[node];
  long long mid = (l + r) / 2;
  return merge2(queryMax(node << 1, l, mid, a, b),
                queryMax(node << 1 | 1, mid + 1, r, a, b));
}
void solve() {
  long long n, m, a, type, y, b, x, k;
  cin >> n >> m;
  for (long long i = 1; i < n + 1; i += 1) {
    cin >> A[i];
    update(1, 1, n, i, A[i]);
  }
  while (m--) {
    cin >> type;
    if (type == 1) {
      cin >> a >> b;
      cout << querySum(1, 1, n, a, b) << "\n";
    } else if (type == 2) {
      cin >> a >> b >> x;
      while (1) {
        long long tmp = queryMax(1, 1, n, a, b);
        if (A[tmp] < x) break;
        y = A[tmp] % x;
        update(1, 1, n, tmp, y);
      }
    } else {
      cin >> k >> x;
      update(1, 1, n, k, x);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  while (t--) {
    solve();
  }
  return 0;
}
