#include using namespace std; using ll=long long; const ll ILL=2167167167167167167; const int INF=2100000000; #define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++) #define all(p) p.begin(),p.end() template using pq_ = priority_queue, greater>; template int LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template int UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template bool chmin(T &a,T b){if(b bool chmax(T &a,T b){if(a void So(vector &v) {sort(v.begin(),v.end());} template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} bool yneos(bool a,bool upp=false){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;} template void vec_out(vector &p,int ty=0){ if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'< T vec_min(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;} template T vec_max(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;} template T vec_sum(vector &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;} int pop_count(long long a){int res=0;while(a){res+=(int)(a&1),a>>=1;}return res;} template T square(T a){return a * a;} #include struct lazy_S { ll sum = 0; ll sz = 0; ll l_val = 0; ll r_val = 0; bool same = true; bool non_zero = false; }; using lazy_F = ll; lazy_S lazy_op(lazy_S l, lazy_S r) { if (l.sz == 0) return r; if (r.sz == 0) return l; if (!r.same || l.r_val != r.l_val) l.same = false; l.r_val = r.r_val; l.sum += r.sum; l.sz += r.sz; if (r.non_zero) l.non_zero = true; return l; } lazy_S lazy_e() { return lazy_S{}; } lazy_S mapping(lazy_F l, lazy_S r) { if (l == -1 || r.sz == 0) return r; r.r_val = l; r.l_val = l; r.sum = r.sz * l; r.same = true; if (l > 1) r.non_zero = true; else r.non_zero = false; return r; } //l(r(x)) lazy_F composition(lazy_F l, lazy_F r) { if (l == -1) return r; return l; } lazy_F lazy_id(){return -1;} #define lazy_calc lazy_S,lazy_op,lazy_e,lazy_F,mapping,composition,lazy_id bool f(lazy_S x) { return !x.non_zero; } bool g(lazy_S x) { return x.same; } void solve(); // DEAR MYSTERIES / TOMOO int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; rep(i, 0, t) solve(); } void solve(){ int N, Q; cin >> N >> Q; const int L = 100'000; auto sqr = [&](int a) -> int { int res = sqrt(a) - 4; chmax(res, 0); while ((res + 1) * (res + 1) <= a) res++; return res; }; vector save(L); rep(i, 1, L) save[i] = sqr(i); vector A(N); rep(i, 0, N) { int a; cin >> a; A[i] = {a, 1, a, a, true, (a > 1)}; } atcoder::lazy_segtree seg(A); while (Q--) { int t, l, r; cin >> t >> l >> r; if (t == 0) { cout << seg.prod(l, r).sum << "\n"; } if (t == 1) { int x; cin >> x; seg.apply(l, r, x); } if (t == 2) { while (l < r) { l = seg.max_right(l); if (l >= r) break; int nx = seg.max_right(l); chmin(nx, r); auto tmp = seg.get(l).l_val; // cout << l << " " << r << " " << nx << endl; seg.apply(l, nx, tmp < L ? save[tmp] : sqr(tmp)); l = nx; } } } }