#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
struct node {
  long long sum, maxn;
};
node tree[MAXN << 2];
long long a[MAXN];
int n, m;
void build(int k, int l, int r) {
  if (l == r) {
    tree[k].sum = a[l];
    tree[k].maxn = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(k << 1, l, mid);
  build(k << 1 | 1, mid + 1, r);
  tree[k].maxn = max(tree[k << 1].maxn, tree[k << 1 | 1].maxn);
  tree[k].sum = tree[k << 1].sum + tree[k << 1 | 1].sum;
}
void change_point(int k, int l, int r, int x, long long y) {
  if (l == r && l == x) {
    tree[k].maxn = y;
    tree[k].sum = y;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    change_point(k << 1, l, mid, x, y);
  else if (x > mid)
    change_point(k << 1 | 1, mid + 1, r, x, y);
  tree[k].sum = tree[k << 1].sum + tree[k << 1 | 1].sum;
  tree[k].maxn = max(tree[k << 1].maxn, tree[k << 1 | 1].maxn);
}
void change_mod(int k, int l, int r, int x, int y, long long mod) {
  if (mod > tree[k].maxn) return;
  if (l == r) {
    tree[k].sum %= mod;
    tree[k].maxn %= mod;
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= x) change_mod(k << 1, l, mid, x, y, mod);
  if (mid < y) change_mod(k << 1 | 1, mid + 1, r, x, y, mod);
  tree[k].sum = tree[k << 1].sum + tree[k << 1 | 1].sum;
  tree[k].maxn = max(tree[k << 1].maxn, tree[k << 1 | 1].maxn);
}
long long query(int k, int l, int r, int x, int y) {
  if (l >= x && r <= y) return tree[k].sum;
  int mid = (l + r) >> 1;
  long long ans = 0;
  if (mid >= x) ans += query(k << 1, l, mid, x, y);
  if (mid < y) ans += query(k << 1 | 1, mid + 1, r, x, y);
  return ans;
}
int main() {
  int cmd, u, v;
  long long w, ans;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  build(1, 1, n);
  for (int i = 0; i < m; i++) {
    scanf("%d", &cmd);
    if (cmd == 3) {
      scanf("%d%lld", &u, &w);
      change_point(1, 1, n, u, w);
    } else if (cmd == 2) {
      scanf("%d%d%lld", &u, &v, &w);
      change_mod(1, 1, n, u, v, w);
    } else if (cmd == 1) {
      scanf("%d%d", &u, &v);
      ans = query(1, 1, n, u, v);
      printf("%lld\n", ans);
    }
  }
  return 0;
}
