#include <bits/stdc++.h>
using namespace std;
const long long Maxn = 1e5 + 5;
long long n, m;
struct Tree {
  long long ext, sum;
} t[Maxn << 2];
void Maintain(long long p) {
  t[p].ext = max(t[p << 1].ext, t[p << 1 | 1].ext);
  t[p].sum = t[p << 1].sum + t[p << 1 | 1].sum;
}
void Build_Tree(long long p, long long l, long long r) {
  if (l == r) {
    scanf("%lld", &t[p].ext);
    t[p].sum = t[p].ext;
    return;
  }
  long long mid = (l + r) >> 1;
  Build_Tree(p << 1, l, mid);
  Build_Tree(p << 1 | 1, mid + 1, r);
  Maintain(p);
}
void Modify_Ths(long long p, long long l, long long r, long long x,
                long long v) {
  if (l == r) {
    t[p].ext = v;
    t[p].sum = v;
    return;
  }
  long long mid = (l + r) >> 1;
  if (mid >= x)
    Modify_Ths(p << 1, l, mid, x, v);
  else
    Modify_Ths(p << 1 | 1, mid + 1, r, x, v);
  Maintain(p);
}
void Modify_Mod(long long p, long long l, long long r, long long x, long long y,
                long long m) {
  if (t[p].ext < m) return;
  if (l == r) {
    t[p].ext %= m;
    t[p].sum %= m;
    return;
  }
  long long mid = (l + r) >> 1;
  if (mid >= x) Modify_Mod(p << 1, l, mid, x, y, m);
  if (mid < y) Modify_Mod(p << 1 | 1, mid + 1, r, x, y, m);
  Maintain(p);
}
long long Query(long long p, long long l, long long r, long long x,
                long long y) {
  if (l > y || r < x) return 0;
  if (l >= x && r <= y) return t[p].sum;
  long long mid = (l + r) >> 1, ret = 0;
  if (mid >= x) ret += Query(p << 1, l, mid, x, y);
  if (mid < y) ret += Query(p << 1 | 1, mid + 1, r, x, y);
  return ret;
}
signed main() {
  scanf("%lld %lld", &n, &m);
  Build_Tree(1, 1, n);
  for (long long i = 0, t, l, r, p; i < m; ++i) {
    scanf("%lld", &t);
    if (t != 3) scanf("%lld %lld", &l, &r);
    if (t == 1)
      printf("%lld\n", Query(1, 1, n, l, r));
    else if (t == 2) {
      scanf("%lld", &p);
      Modify_Mod(1, 1, n, l, r, p);
    } else {
      scanf("%lld %lld", &t, &p);
      Modify_Ths(1, 1, n, t, p);
    }
  }
  return 0;
}
