#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
struct jz {
  int L, R, mi;
  long long x;
} a[maxn * 4];
int n, m, w[maxn];
inline int _read() {
  int num = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') num = num * 10 + ch - 48, ch = getchar();
  return num;
}
void up(int x) {
  a[x].mi = max(a[x * 2].mi, a[x * 2 + 1].mi);
  a[x].x = a[x * 2].x + a[x * 2 + 1].x;
}
void Build(int x, int L, int R) {
  a[x].L = L;
  a[x].R = R;
  if (L == R) {
    a[x].mi = w[L];
    a[x].x = w[L];
    return;
  }
  int mid = L + (R - L >> 1);
  Build(x * 2, L, mid);
  Build(x * 2 + 1, mid + 1, R);
  up(x);
}
void change(int x, int L, int R, int y) {
  if (a[x].mi < y) return;
  if (a[x].L == a[x].R) {
    a[x].mi %= y;
    a[x].x = a[x].mi;
    return;
  }
  int mid = a[x].L + (a[x].R - a[x].L >> 1);
  if (R <= mid)
    change(x * 2, L, R, y);
  else if (L > mid)
    change(x * 2 + 1, L, R, y);
  else
    change(x * 2, L, mid, y), change(x * 2 + 1, mid + 1, R, y);
  up(x);
}
void op(int x, int w, int y) {
  if (a[x].L == a[x].R) {
    a[x].mi = y;
    a[x].x = a[x].mi;
    return;
  }
  int mid = a[x].L + (a[x].R - a[x].L >> 1);
  if (w <= mid)
    op(x * 2, w, y);
  else
    op(x * 2 + 1, w, y);
  up(x);
}
long long ask(int x, int L, int R) {
  if (L == a[x].L && R == a[x].R) return a[x].x;
  int mid = a[x].L + (a[x].R - a[x].L >> 1);
  if (R <= mid)
    return ask(x * 2, L, R);
  else if (L > mid)
    return ask(x * 2 + 1, L, R);
  else
    return ask(x * 2, L, mid) + ask(x * 2 + 1, mid + 1, R);
}
int main() {
  n = _read();
  m = _read();
  for (int i = 1; i <= n; i++) w[i] = _read();
  Build(1, 1, n);
  while (m--) {
    int h = _read(), L = _read(), R = _read(), x;
    if (h == 1) printf("%lld\n", ask(1, L, R));
    if (h == 2) x = _read(), change(1, L, R, x);
    if (h == 3) op(1, L, R);
  }
}
