#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 7;
int a[MAX], n, m;
pair<long long int, long long int> t[4 * MAX];
pair<long long int, long long int> operator+(
    pair<long long int, long long int> a,
    pair<long long int, long long int> b) {
  return {a.first + b.first, max(a.second, b.second)};
}
pair<long long int, long long int> build(int id = 1, int st = 1, int ed = n) {
  if (st == ed) return t[id] = {a[st], a[st]};
  int piv = (st + ed) >> 1;
  return t[id] = build(id << 1, st, piv) + build(id << 1 | 1, piv + 1, ed);
}
pair<long long int, long long int> upd1(int p, long long int x, int id = 1,
                                        int st = 1, int ed = n) {
  if (p > ed || p < st) return t[id];
  if (st == ed) return t[id] = {x, x};
  int piv = (st + ed) >> 1;
  return t[id] = upd1(p, x, id << 1, st, piv) +
                 upd1(p, x, id << 1 | 1, piv + 1, ed);
}
pair<long long int, long long int> upd2(int qx, int qy, int md, int id = 1,
                                        int st = 1, int ed = n) {
  if (qx > ed || qy < st) return t[id];
  if (t[id].second < md) return t[id];
  if (st == ed) return t[id] = {t[id].first % md, t[id].first % md};
  int piv = (st + ed) >> 1;
  return t[id] = upd2(qx, qy, md, id << 1, st, piv) +
                 upd2(qx, qy, md, id << 1 | 1, piv + 1, ed);
}
long long int qry(int qx, int qy, int id = 1, int st = 1, int ed = n) {
  if (qx > ed || qy < st) return 0;
  if (qx <= st && ed <= qy) return t[id].first;
  int piv = (st + ed) >> 1;
  return qry(qx, qy, id << 1, st, piv) + qry(qx, qy, id << 1 | 1, piv + 1, ed);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = (1); i <= (n); ++i) cin >> a[i];
  build();
  while (m--) {
    int tp;
    cin >> tp;
    if (tp == 1) {
      int x, y;
      cin >> x >> y;
      cout << qry(x, y) << '\n';
    } else if (tp == 2) {
      int x, y, md;
      cin >> x >> y >> md;
      upd2(x, y, md);
    } else {
      int p, x;
      cin >> p >> x;
      upd1(p, x);
    }
  }
  return 0;
}
