#include <bits/stdc++.h>
using namespace std;
const int MX = 2 * 1e5 + 10;
int N, M;
long long arr[MX];
pair<long long, long long> st[4 * MX];
void merge(int L, int R, int p) {
  st[p].first = st[p * 2].first + st[p * 2 + 1].first;
  int lc = st[p * 2].second, rc = st[p * 2 + 1].second;
  if (arr[lc] >= arr[rc])
    st[p].second = lc;
  else
    st[p].second = rc;
}
void B(int L, int R, int p) {
  if (L == R) {
    st[p].first = arr[L];
    st[p].second = L;
    return;
  }
  int mid = (L + R) / 2;
  B(L, mid, p * 2);
  B(mid + 1, R, p * 2 + 1);
  merge(L, R, p);
}
pair<long long, long long> Q(int L, int R, int p, int i, int j) {
  if (L > R || i > R || j < L) return {0, -1};
  if (L >= i && R <= j) {
    return st[p];
  }
  pair<long long, long long> q1, q2;
  int mid = L + R;
  mid /= 2;
  q1 = Q(L, mid, p * 2, i, j);
  q2 = Q(mid + 1, R, p * 2 + 1, i, j);
  if (q2.second == -1)
    return {q1.first + q2.first, q1.second};
  else if (q1.second == -1)
    return {q1.first + q2.first, q2.second};
  else if (arr[q2.second] >= arr[q1.second])
    return {q1.first + q2.first, q2.second};
  return {q1.first + q2.first, q1.second};
}
void U(int L, int R, int p, int i, int j, int val) {
  if (L > R || i > R || j < L) return;
  if (L >= i && R <= j) {
    st[p].first = val;
    if (L == R) arr[L] = val;
    return;
  }
  int mid = L + R;
  mid /= 2;
  U(L, mid, p * 2, i, j, val);
  U(mid + 1, R, p * 2 + 1, i, j, val);
  merge(L, R, p);
}
void up(int L, int R, int x) {
  pair<long long, long long> ans = Q(0, N - 1, 1, L, R);
  if (arr[ans.second] < x) return;
  U(0, N - 1, 1, ans.second, ans.second, arr[ans.second] % x);
  up(L, R, x);
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) {
    int x;
    scanf("%d", &x);
    arr[i] = (long long)x;
  }
  B(0, N - 1, 1);
  for (int i = 0; i < M; i++) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int l, r;
      scanf("%d%d", &l, &r);
      cout << Q(0, N - 1, 1, l - 1, r - 1).first << "\n";
    } else if (t == 2) {
      int l, r, x;
      scanf("%d%d%d", &l, &r, &x);
      up(l - 1, r - 1, x);
    } else {
      int k, x;
      scanf("%d%d", &k, &x);
      U(0, N - 1, 1, k - 1, k - 1, x);
    }
  }
}
