#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;
long long sum[MAX_N], tree[MAX_N << 2], lazy[MAX_N << 2], a[MAX_N],
    tmax[MAX_N << 2];
inline void push_up(int p) {
  tree[p] = tree[p << 1] + tree[p << 1 | 1];
  tmax[p] = max(tmax[p << 1], tmax[p << 1 | 1]);
}
void build(int l, int r, int p) {
  if (l == r) {
    int num;
    cin >> num;
    tree[p] = num;
    tmax[p] = num;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, p << 1), build(mid + 1, r, p << 1 | 1);
  push_up(p);
}
long long query(int l, int r, int p, int L, int R) {
  if (L <= l && r <= R) return tree[p];
  int mid = (l + r) >> 1;
  long long ret = 0;
  if (L <= mid) ret += query(l, mid, p << 1, L, R);
  if (R > mid) ret += query(mid + 1, r, p << 1 | 1, L, R);
  return ret;
}
void update(int l, int r, int p, int L, int R, int s) {
  if (tmax[p] < s) return;
  if (L <= l && r <= R && l == r) {
    tree[p] %= s;
    tmax[p] %= s;
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) update(l, mid, p << 1, L, R, s);
  if (R > mid) update(mid + 1, r, p << 1 | 1, L, R, s);
  push_up(p);
}
void update(int i, int p, int l, int r, int s) {
  if (l == r) {
    tree[p] = s;
    tmax[p] = s;
    return;
  }
  int mid = (l + r) >> 1;
  if (i <= mid)
    update(i, p << 1, l, mid, s);
  else
    update(i, p << 1 | 1, mid + 1, r, s);
  push_up(p);
}
int main() {
  int n, m, x, y, z, ch;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  build(1, n, 1);
  while (m--) {
    cin >> ch >> x >> y;
    if (ch == 1)
      cout << query(1, n, 1, x, y) << endl;
    else if (ch == 2) {
      cin >> z;
      update(1, n, 1, x, y, z);
    } else
      update(x, 1, 1, n, y);
  }
  return 0;
}
