#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
int n, m;
long long a[maxn];
struct seg {
  struct no {
    int l, r;
    long long sum, maxnum;
  } node[maxn << 1];
  inline void up(int now) {
    node[now].sum = node[(now << 1)].sum + node[(now << 1 | 1)].sum;
    node[now].maxnum =
        max(node[(now << 1)].maxnum, node[(now << 1 | 1)].maxnum);
    return;
  }
  void build(int l, int r, int now) {
    node[now].l = l, node[now].r = r;
    if (l == r) return (void)(node[now].sum = node[now].maxnum = a[l]);
    build(l, ((l + r) >> 1), (now << 1)),
        build(((l + r) >> 1) + 1, r, (now << 1 | 1));
    up(now);
    return;
  }
  void chenge(int l, int r, int now, int p) {
    if (node[now].l > r or node[now].r < l) return;
    if (node[now].maxnum < p) return;
    if (node[now].l == node[now].r)
      return (void)(node[now].sum %= p, node[now].maxnum %= p);
    chenge(l, r, (now << 1), p), chenge(l, r, (now << 1 | 1), p);
    up(now);
    return;
  }
  void change(int l, int r, int now, int val) {
    if (node[now].l > r or node[now].r < l) return;
    if (node[now].l == node[now].r)
      return (void)(node[now].sum = node[now].maxnum = val);
    change(l, r, (now << 1), val), change(l, r, (now << 1 | 1), val);
    up(now);
    return;
  }
  void quary(int l, int r, int now, long long &ans) {
    if (node[now].l > r or node[now].r < l) return;
    if (l <= node[now].l and node[now].r <= r)
      return (void)(ans += node[now].sum);
    quary(l, r, (now << 1), ans), quary(l, r, (now << 1 | 1), ans);
    up(now);
    return;
  }
} tree;
long long read_long() {
  long long x = 0, f = 1;
  char ch;
  while (!isdigit(ch = getchar())) (ch == '-') and (f = -1);
  for (x = ch ^ 48; isdigit(ch = getchar());
       x = (x << 1) + (x << 3) + (ch ^ 48))
    ;
  return x * f;
}
int read_int() {
  int x = 0, f = 1;
  char ch;
  while (!isdigit(ch = getchar())) (ch == '-') and (f = -1);
  for (x = ch ^ 48; isdigit(ch = getchar());
       x = (x << 1) + (x << 3) + (ch ^ 48))
    ;
  return x * f;
}
signed main() {
  n = read_int(), m = read_int();
  for (int i = 1; i <= n; i++) {
    a[i] = read_long();
  }
  tree.build(1, n, 1);
  for (int opt, x, y, z; m; m--) {
    opt = read_int();
    if (opt == 1) {
      x = read_int(), y = read_int();
      long long ans = 0;
      tree.quary(x, y, 1, ans);
      printf("%lld\n", ans);
    }
    if (opt == 2) {
      x = read_int(), y = read_int(), z = read_int();
      tree.chenge(x, y, 1, z);
    }
    if (opt == 3) {
      x = read_int(), y = read_int();
      tree.change(x, x, 1, y);
    }
  }
  return 0;
}
