#include using namespace std; constexpr int sz = 256; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, q; cin >> n >> q; vector a(n); for (auto&& e : a) { cin >> e; } int m = (n + sz - 1) / sz; struct block { int gcd = 0; int assign = -1; long long sum = 0; map mp; }; vector b(m); auto build = [&](int k) { b[k].gcd = 0; b[k].assign = -1; b[k].sum = 0; b[k].mp.clear(); for (int i = k * sz; i < min((k + 1) * sz, n); ++i) { ++b[k].mp[a[i]]; b[k].sum += a[i]; } }; auto push = [&](int k) { for (int i = k * sz; i < min((k + 1) * sz, n); ++i) { a[i] = b[k].assign == -1 ? __gcd(a[i], b[k].gcd) : b[k].assign; } }; auto run = [&](int l, int r, auto fa, auto fb) { if (l % sz) { push(l / sz); while (l < r and l % sz) fa(l++); build((l - 1) / sz); } if (r % sz) { push(r / sz); while (l < r and r % sz) fa(--r); build(r / sz); } for (; l < r; l += sz) fb(l / sz); }; for (int k = 0; k < m; ++k) build(k); while (q--) { int tp, l, r; cin >> tp >> l >> r; --l; if (tp == 1) { int x; cin >> x; run(l, r, [&](int i) { a[i] = x; }, [&](int k) { b[k].assign = x; b[k].mp.clear(); int len = min(sz, n - k * sz); b[k].mp[x] = len; b[k].sum = (long long)x * len; }); } else if (tp == 2) { int x; cin >> x; run(l, r, [&](int i) { a[i] = __gcd(a[i], x); }, [&](int k) { if (b[k].assign == -1) { b[k].gcd = __gcd(b[k].gcd, x); } else { b[k].assign = __gcd(b[k].assign, x); } map nmp; for (auto e : b[k].mp) { nmp[__gcd(e.first, x)] += e.second; } swap(b[k].mp, nmp); b[k].sum = 0; for (auto e : b[k].mp) { b[k].sum += (long long)e.first * e.second; } }); } else if (tp == 3) { int res = -1; run(l, r, [&](int i) { res = max(res, a[i]); }, [&](int k) { res = max(res, prev(end(b[k].mp))->first); }); cout << res << '\n'; } else { long long res = 0; run(l, r, [&](int i) { res += a[i]; }, [&](int k) { res += b[k].sum; }); cout << res << '\n'; } } }