#include <bits/stdc++.h>
using namespace std;
int N, Q;
int A[100005];
int lazy[400005];
long long sum[400005];
int mx[400005], mn[400005];
void build(int n, int l, int r) {
  lazy[n] = -1;
  if (l == r) {
    sum[n] = mx[n] = mn[n] = A[l];
    return;
  }
  int mid = (l + r) >> 1;
  int le = (n << 1), ri = (n << 1 | 1);
  build(le, l, mid);
  build(ri, mid + 1, r);
  mx[n] = max(mx[le], mx[ri]);
  mn[n] = min(mn[le], mn[ri]);
  sum[n] = sum[le] + sum[ri];
}
void unlazy(int n, int l, int r) {
  if (lazy[n] == -1) return;
  sum[n] = lazy[n] * (r - l + 1LL);
  mx[n] = mn[n] = lazy[n];
  if (l != r) {
    lazy[(n << 1)] = lazy[n];
    lazy[(n << 1 | 1)] = lazy[n];
  }
  lazy[n] = -1;
}
long long query(int n, int l, int r, int ql, int qr) {
  unlazy(n, l, r);
  if (qr < l || r < ql) return 0;
  if (ql <= l && r <= qr) {
    return sum[n];
  }
  int mid = (l + r) >> 1;
  long long res = 0;
  res += query((n << 1), l, mid, ql, qr);
  res += query((n << 1 | 1), mid + 1, r, ql, qr);
  return res;
}
void upd2(int n, int l, int r, int ql, int qr, int x) {
  unlazy(n, l, r);
  if (qr < l || r < ql || mx[n] < x) return;
  if (ql <= l && r <= qr && mx[n] == mn[n]) {
    lazy[n] = mx[n] % x;
    unlazy(n, l, r);
    return;
  }
  int mid = (l + r) >> 1;
  int le = (n << 1), ri = (n << 1 | 1);
  upd2(le, l, mid, ql, qr, x);
  upd2(ri, mid + 1, r, ql, qr, x);
  mx[n] = max(mx[le], mx[ri]);
  mn[n] = min(mn[le], mn[ri]);
  sum[n] = sum[le] + sum[ri];
}
void upd3(int n, int l, int r, int pos, int val) {
  unlazy(n, l, r);
  if (pos < l || pos > r) return;
  if (l == r) {
    sum[n] = mx[n] = mn[n] = val;
    return;
  }
  int mid = (l + r) >> 1;
  int le = (n << 1), ri = (n << 1 | 1);
  upd3(le, l, mid, pos, val);
  upd3(ri, mid + 1, r, pos, val);
  mx[n] = max(mx[le], mx[ri]);
  mn[n] = min(mn[le], mn[ri]);
  sum[n] = sum[le] + sum[ri];
}
int main() {
  scanf("%d %d", &N, &Q);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
  }
  build(1, 1, N);
  int ty, l, r, val, pos, x;
  while (Q--) {
    scanf("%d", &ty);
    if (ty == 1) {
      scanf("%d %d", &l, &r);
      printf("%lld\n", query(1, 1, N, l, r));
    } else if (ty == 2) {
      scanf("%d %d %d", &l, &r, &x);
      upd2(1, 1, N, l, r, x);
    } else {
      scanf("%d %d", &pos, &val);
      upd3(1, 1, N, pos, val);
    }
  }
  cin >> N;
}
