#include <bits/stdc++.h>
using namespace std;
long long int arr[100003];
struct node {
  long long int max;
  long long int sum;
} t[4 * 100003];
void build(long long int node, long long int start, long long int end) {
  if (start == end) {
    t[node].sum = arr[start];
    t[node].max = arr[start];
  } else {
    long long int mid = (start + end) / 2;
    build(2 * node, start, mid);
    build(2 * node + 1, mid + 1, end);
    t[node].max = max(t[2 * node].max, t[2 * node + 1].max);
    t[node].sum = t[2 * node].sum + t[2 * node + 1].sum;
  }
}
void updateRange(long long int node, long long int start, long long int end,
                 long long int l, long long int r, long long int val) {
  if (t[node].max < val) return;
  if (start == end) {
    t[node].sum = t[node].sum % val;
    t[node].max = t[node].max % val;
    return;
  }
  long long int mid = (start + end) / 2;
  if (l <= mid) updateRange(2 * node, start, mid, l, r, val);
  if (r > mid) updateRange(2 * node + 1, mid + 1, end, l, r, val);
  t[node].max = max(t[2 * node].max, t[2 * node + 1].max);
  t[node].sum = t[2 * node].sum + t[2 * node + 1].sum;
  return;
}
void update(long long int node, long long int start, long long int end,
            long long int idx, long long int val) {
  if (start == end) {
    t[node].max = val;
    t[node].sum = val;
  } else {
    long long int mid = (start + end) / 2;
    if (idx <= mid)
      update(2 * node, start, mid, idx, val);
    else
      update(2 * node + 1, mid + 1, end, idx, val);
    t[node].max = max(t[2 * node].max, t[2 * node + 1].max);
    t[node].sum = t[2 * node].sum + t[2 * node + 1].sum;
  }
}
long long int query(long long int node, long long int start, long long int end,
                    long long int l, long long int r) {
  if (start >= l and end <= r) return t[node].sum;
  long long int mid = (start + end) / 2;
  long long int ans = 0;
  if (l <= mid) ans += query(2 * node, start, mid, l, r);
  if (r > mid) ans += query(2 * node + 1, mid + 1, end, l, r);
  return ans;
}
signed main() {
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 1; i <= n; i++) cin >> arr[i];
  build(1, 1, n);
  while (m--) {
    long long int type;
    cin >> type;
    if (type == 1) {
      long long int l, r;
      cin >> l >> r;
      cout << query(1, 1, n, l, r) << endl;
    } else if (type == 2) {
      long long int l, r, mod;
      cin >> l >> r >> mod;
      updateRange(1, 1, n, l, r, mod);
    } else {
      long long int pos, val;
      cin >> pos >> val;
      update(1, 1, n, pos, val);
    }
  }
  return 0;
}
