#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long n, m, a[N], T[4 * N], max_value[4 * N];
void build(long long l = 1, long long r = n, long long u = 1) {
  if (l == r) {
    T[u] = a[l];
    max_value[u] = a[l];
    return;
  }
  long long m = (l + r) >> 1;
  build(l, m, u * 2);
  build(m + 1, r, u * 2 + 1);
  max_value[u] = max(max_value[u * 2], max_value[u * 2 + 1]);
  T[u] = T[u * 2] + T[u * 2 + 1];
}
void upd1(long long x, long long ll, long long rr, long long l = 1,
          long long r = n, long long u = 1) {
  if (l > rr || r < ll || max_value[u] < x) return;
  if (l == r) {
    a[l] %= x;
    T[u] = a[l];
    max_value[u] = a[l];
    return;
  }
  long long m = (l + r) >> 1;
  upd1(x, ll, rr, l, m, u * 2);
  upd1(x, ll, rr, m + 1, r, u * 2 + 1);
  T[u] = T[u * 2] + T[u * 2 + 1];
  max_value[u] = max(max_value[u * 2], max_value[u * 2 + 1]);
}
void upd2(long long p, long long x, long long l = 1, long long r = n,
          long long u = 1) {
  if (l > p || r < p) return;
  if (l == r) {
    a[l] = x;
    T[u] = a[l];
    max_value[u] = a[l];
    return;
  }
  long long m = (l + r) >> 1;
  upd2(p, x, l, m, u * 2);
  upd2(p, x, m + 1, r, u * 2 + 1);
  T[u] = T[u * 2] + T[u * 2 + 1];
  max_value[u] = max(max_value[u * 2], max_value[u * 2 + 1]);
}
long long get(long long ll, long long rr, long long l = 1, long long r = n,
              long long u = 1) {
  if (l > rr || r < ll) return 0;
  if (l >= ll && r <= rr) return T[u];
  long long m = (l + r) >> 1;
  return get(ll, rr, l, m, u * 2) + get(ll, rr, m + 1, r, u * 2 + 1);
}
void local_run() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  build();
  while (m--) {
    long long v, l, r, x;
    cin >> v >> l >> r;
    if (v == 1)
      cout << get(l, r) << '\n';
    else if (v == 2) {
      cin >> x;
      upd1(x, l, r);
    } else
      upd2(l, r);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  local_run();
}
