#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 1e6 + 5;
long long n, m, q, a[N];
struct node {
  long long sum, modtag;
  long long left, right;
} tr[N << 2];
inline long long ls(long long pos) { return pos << 1; }
inline long long rs(long long pos) { return pos << 1 | 1; }
inline void push_up(long long pos) {
  tr[pos].modtag = max(tr[ls(pos)].modtag, tr[rs(pos)].modtag);
  tr[pos].sum = tr[ls(pos)].sum + tr[rs(pos)].sum;
  return;
}
void build(long long pos, long long l, long long r) {
  tr[pos].left = l;
  tr[pos].right = r;
  if (l == r) {
    tr[pos].sum = tr[pos].modtag = a[l];
    return;
  }
  long long mid = (l + r) >> 1;
  build(ls(pos), l, mid);
  build(rs(pos), mid + 1, r);
  push_up(pos);
}
void update_mod(long long pos, long long L, long long R, long long sign) {
  if (tr[pos].modtag < sign) return;
  if (tr[pos].left == tr[pos].right) {
    tr[pos].sum %= sign;
    tr[pos].modtag %= sign;
    return;
  }
  long long mid = (tr[pos].left + tr[pos].right) >> 1;
  if (L <= mid) update_mod(ls(pos), L, R, sign);
  if (R > mid) update_mod(rs(pos), L, R, sign);
  push_up(pos);
}
void update_add(long long pos, long long L, long long R, long long sign) {
  if (tr[pos].left == tr[pos].right) {
    tr[pos].sum = tr[pos].modtag = sign;
    return;
  }
  long long mid = (tr[pos].right + tr[pos].left) >> 1;
  if (L <= mid) update_add(ls(pos), L, R, sign);
  if (R > mid) update_add(rs(pos), L, R, sign);
  push_up(pos);
}
long long query(long long pos, long long L, long long R) {
  if (L <= tr[pos].left && tr[pos].right <= R) return tr[pos].sum;
  long long ans = 0, mid = (tr[pos].left + tr[pos].right) >> 1;
  if (L <= mid) ans += query(ls(pos), L, R);
  if (R > mid) ans += query(rs(pos), L, R);
  return ans;
}
inline long long read() {
  long long a = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) a = (a << 3) + (a << 1) + ch - '0';
  return a * f;
}
signed main() {
  n = read(), q = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  build(1, 1, n);
  while (q--) {
    long long opt = read(), x = read(), y = read();
    if (opt == 1)
      printf("%lld\n", query(1, x, y));
    else if (opt == 2)
      update_mod(1, x, y, read());
    else
      update_add(1, x, x, y);
  }
  return 0;
}
