#include <bits/stdc++.h>
using namespace std;
struct Node {
  long long maxx, sum;
} node[100010 << 2];
void pushup(int rt) {
  node[rt].maxx = max(node[rt << 1].maxx, node[rt << 1 | 1].maxx);
  node[rt].sum = node[rt << 1].sum + node[rt << 1 | 1].sum;
}
void build(int l, int r, int rt) {
  if (l == r) {
    scanf("%lld", &node[rt].maxx);
    node[rt].sum = node[rt].maxx;
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
  pushup(rt);
}
void point_update(int index, int k, int l, int r, int rt) {
  if (l == r) {
    node[rt].maxx = k;
    node[rt].sum = k;
    return;
  }
  int m = (l + r) >> 1;
  if (index <= m)
    point_update(index, k, l, m, rt << 1);
  else
    point_update(index, k, m + 1, r, rt << 1 | 1);
  pushup(rt);
}
void interval_update(int L, int R, int mod, int l, int r, int rt) {
  if (L > r || R < l) return;
  if (node[rt].maxx < mod) return;
  if (l == r) {
    node[rt].sum %= mod;
    node[rt].maxx = node[rt].sum;
    return;
  }
  int m = (l + r) >> 1;
  interval_update(L, R, mod, l, m, rt << 1);
  interval_update(L, R, mod, m + 1, r, rt << 1 | 1);
  pushup(rt);
}
long long query(int L, int R, int l, int r, int rt) {
  if (L > r || R < l) return 0;
  if (L <= l && r <= R) return node[rt].sum;
  long long sum = 0;
  int m = (l + r) >> 1;
  sum += query(L, R, l, m, rt << 1);
  sum += query(L, R, m + 1, r, rt << 1 | 1);
  return sum;
}
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  build(1, n, 1);
  while (m--) {
    int opt, l, r, mod;
    scanf("%d", &opt);
    if (opt == 3) {
      scanf("%d%d", &l, &r);
      point_update(l, r, 1, n, 1);
    }
    if (opt == 2) {
      scanf("%d%d%d", &l, &r, &mod);
      interval_update(l, r, mod, 1, n, 1);
    }
    if (opt == 1) {
      scanf("%d%d", &l, &r);
      printf("%lld\n", query(l, r, 1, n, 1));
    }
  }
  return 0;
}
