#include #include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } using mint = atcoder::modint998244353; ll ipow(ll x, int a) { ll res = 1; while (a) { if (a & 1) res *= x; x *= x; a >>= 1; } return res; } ll isqrt(ll n) { if (n <= 0) return 0; ll x = sqrt(n); if (x * x > n) x--; return x; } // template atcoder lazy segtree struct S { ll sm, sz; deque d; }; S op(S a, S b) { a.sm += b.sm; a.sz += a.sz; if (a.d.size() < b.d.size()) swap(a.d, b.d); rep(i, 0, b.d.size()) a.d[i] += b.d[i]; return a; } S e() { return {0, 0, {}}; } struct F { int a, c; deque d; }; S mapping(F f, S x) { if (f.c > 0) { int ln = min(f.c, (int)x.d.size()); rep(lp, 0, ln) { x.sm -= x.d.front(); x.d.pop_front(); } return x; } if (f.a >= 0) { x.sm = x.sz * f.a; x.d.clear(); for (int v : f.d) x.d.push_back(x.sz * v); } return x; } F comp(F f, F g) { if (f.a >= 0) return f; if (f.c > 0) { g.c += f.c; } if (g.a >= 0) { int ln = min(g.c, (int)g.d.size()); rep(lp, 0, ln) { g.a -= g.d.front(); g.d.pop_front(); } g.c = 0; } return g; } F id() { return {-1, 0, {}}; } using segtree = atcoder::lazy_segtree; deque build_deq(ll x) { deque res; rep(i, 0, 100) { ll y = isqrt(x); if (x == y) break; res.push_back(x - y); x = y; } return res; } void solve() { int n, q; cin >> n >> q; vector a(n); rep(i, 0, n) cin >> a[i]; segtree seg; { vector tmp(n); rep(i, 0, n) tmp[i] = S{a[i], 1, build_deq((ll)a[i])}; seg = segtree{tmp}; } while (q--) { int t, l, r; cin >> t >> l >> r; if (t == 0) cout << seg.prod(l, r).sm << '\n'; if (t == 1) { int x; cin >> x; seg.apply(l, r, F{x, 0, build_deq(x)}); } if (t == 2) seg.apply(l, r, F{-1, 1, {}}); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int t = 1; // cin >> t; while (t--) solve(); }