#include <bits/stdc++.h>
using namespace std;
void dout() { cerr << endl; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
  cerr << H << ' ';
  dout(T...);
}
using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
template <typename T>
void do_uniq(vector<T> &vec) {
  sort((vec).begin(), (vec).end());
  vec.resize(unique((vec).begin(), (vec).end()) - vec.begin());
}
int mod = 1e9 + 7;
int ml(int a, int b) { return (a * 1ll * b) % mod; }
int add(int a, int b) { return (a + b) % mod; }
int sub(int a, int b) { return add(a, mod - b); }
int sq(int a) { return ml(a, a); }
int b_p(int b, int p) {
  if (p == 0) return 1;
  if (p & 1) return ml(b, b_p(b, p - 1));
  return sq(b_p(b, p >> 1));
}
ld INF = 1000;
const int MAXN = 1e5 + 12;
ll mx[8 * MAXN];
ll sm[8 * MAXN];
void update(int v, int l, int r, int tl, int tr, int mod) {
  if (tl > tr) return;
  if (mx[v] < mod) return;
  if (l == r) {
    sm[v] %= mod;
    mx[v] %= mod;
    return;
  }
  int mid = (l + r) >> 1;
  update(2 * v, l, mid, tl, min(mid, tr), mod);
  update(1 + 2 * v, mid + 1, r, max(mid + 1, tl), tr, mod);
  mx[v] = max(mx[2 * v], mx[2 * v + 1]);
  sm[v] = sm[2 * v] + sm[2 * v + 1];
}
ll sum(int v, int l, int r, int tl, int tr) {
  if (tl > tr) return 0;
  if (tl == l && tr == r) return sm[v];
  int mid = (l + r) >> 1;
  return sum(2 * v, l, mid, tl, min(mid, tr)) +
         sum(1 + 2 * v, mid + 1, r, max(mid + 1, tl), tr);
}
void sett(int v, int l, int r, int pos, int x) {
  if (l == r) {
    mx[v] = sm[v] = x;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    sett(v * 2, l, mid, pos, x);
  else
    sett(1 + 2 * v, mid + 1, r, pos, x);
  mx[v] = max(mx[2 * v], mx[2 * v + 1]);
  sm[v] = sm[2 * v] + sm[2 * v + 1];
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int curr;
    cin >> curr;
    sett(1, 0, n - 1, i, curr);
  }
  for (int i = 0; i < m; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      int l, r;
      cin >> l >> r;
      --l;
      --r;
      cout << sum(1, 0, n - 1, l, r) << "\n";
    } else if (t == 2) {
      int l, r, x;
      cin >> l >> r >> x;
      --l;
      --r;
      update(1, 0, n - 1, l, r, x);
    } else {
      int k, x;
      cin >> k >> x;
      --k;
      sett(1, 0, n - 1, k, x);
    }
  }
}
void multisolve() {
  int t;
  cin >> t;
  int i = 1;
  while (t--) {
    solve();
    i++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cout << fixed << setprecision(20);
  solve();
}
