1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| #include <bits/stdc++.h> using namespace std; #define LL long long #define ULL unsigned long long #define Pair pair<LL ,LL > #define ls rt<<1 #define rs rt<<1|1 #define PI acos(-1.0) #define eps 1e-8 #define mod 998244353 #define MAXN 50001 #define MS 100005
int n,m,k; struct node{ bitset<111> c; int sum; int la; }p[MS<<2];
bitset<111> change(int x){ bitset<111> t; t.reset(); for(int i=2;i*i<=x;i++){ if(!(x%i)){ t[i] = 1; while(!(x%i)) x/=i; } } if(x!=1) t[x] = 1; return t; }
int cal(int w, bitset<111> t){ for(int pos=t._Find_next(1); pos!=111; pos=t._Find_next(pos)) w = w/pos*(pos-1); return w; }
void push_up(int rt){ p[rt].sum = (p[ls].sum + p[rs].sum)%mod; p[rt].c = p[ls].c & p[rs].c; }
void push_down(int rt){ if(p[rt].la != 1){ int t = p[rt].la; p[ls].sum = 1LL*p[ls].sum*t%mod; p[rs].sum = 1LL*p[rs].sum*t%mod; p[ls].la = 1LL*p[ls].la*t%mod; p[rs].la = 1LL*p[rs].la*t%mod; p[rt].la = 1; } }
void build(int l,int r,int rt){ p[rt].la = 1; if(l == r){ int x; cin >> x; p[rt].c = change(x); p[rt].sum = cal(x,p[rt].c); return; } int m = l+r>>1; build(l,m,ls); build(m+1,r,rs); push_up(rt); }
void modify(int L,int R,int l,int r,int rt,int w,bitset<111> cc){ if(L <= l && r <= R){ if((p[rt].c|cc) == p[rt].c){ p[rt].sum = 1LL*p[rt].sum*w%mod; p[rt].la = 1LL*p[rt].la*w%mod; return; } } if(l == r){ bitset<111> t = (p[rt].c|cc)^p[rt].c; p[rt].sum = 1LL*p[rt].sum*cal(w,t)%mod; p[rt].c |= cc; return; } int m = l+r>>1; push_down(rt); if(m >= L) modify(L,R,l,m,ls,w,cc); if(m < R) modify(L,R,m+1,r,rs,w,cc); push_up(rt); }
int query(int L,int R,int l,int r,int rt){ if(L <= l && r <= R) return p[rt].sum; int m = l+r>>1, ans = 0; push_down(rt); if(m >= L) ans = (ans + query(L,R,l,m,ls) )%mod; if(m < R) ans = (ans + query(L,R,m+1,r,rs) )%mod; return ans; }
void solve() { cin >> n >> m; build(1,n,1); while(m--){ int op,l,r,w; cin >> op >> l >> r; if(!op) cin >> w, modify(l,r,1,n,1,w,change(w)); else cout << query(l,r,1,n,1) << "\n"; } }
int main() { ios::sync_with_stdio(false); int ce = 1;
while(ce--) { solve(); }
return 0; }
|