#include <bits/stdc++.h>
using namespace std;
long long sum[100005 << 2], maxx[100005 << 2];
long long a[100005];
void pushup(int o) {
  sum[o] = sum[o << 1] + sum[o << 1 | 1];
  maxx[o] = max(maxx[o << 1], maxx[o << 1 | 1]);
}
void build(int o, int l, int r) {
  if (l == r) {
    sum[o] = a[l];
    maxx[o] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(o << 1, l, mid);
  build(o << 1 | 1, mid + 1, r);
  pushup(o);
}
void change1(int o, int l, int r, int ql, int qr, int v) {
  if (maxx[o] < v) return;
  if (l == r) {
    sum[o] %= v;
    maxx[o] = sum[o];
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= ql) change1(o << 1, l, mid, ql, qr, v);
  if (mid < qr) change1(o << 1 | 1, mid + 1, r, ql, qr, v);
  pushup(o);
}
void change2(int o, int l, int r, int t, int v) {
  if (l == r) {
    sum[o] = v;
    maxx[o] = v;
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= t)
    change2(o << 1, l, mid, t, v);
  else
    change2(o << 1 | 1, mid + 1, r, t, v);
  pushup(o);
}
long long querysum(int o, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return sum[o];
  long long ans = 0;
  int mid = (l + r) >> 1;
  if (mid >= ql) ans += querysum(o << 1, l, mid, ql, qr);
  if (mid < qr) ans += querysum(o << 1 | 1, mid + 1, r, ql, qr);
  return ans;
}
int main() {
  register int i;
  int n, m;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%lld", &a[i]);
  build(1, 1, n);
  for (i = 1; i <= m; i++) {
    int t, l, r, v;
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d%d", &l, &r);
      printf("%lld\n", querysum(1, 1, n, l, r));
    }
    if (t == 2) {
      scanf("%d%d%d", &l, &r, &v);
      change1(1, 1, n, l, r, v);
    }
    if (t == 3) {
      scanf("%d%d", &l, &v);
      change2(1, 1, n, l, v);
    }
  }
  return 0;
}
