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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
| #include <bits/stdc++.h> #define int long long #define endl '\n' #define ls u<<1 #define rs u<<1|1 #define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) using namespace std; typedef long long ll; const ll mod=998244353; const int N=2e5+100; typedef long long ll; int n,m; int arr[N],fa[26][N]; struct node { int l,r; ll val; } tr[N<<2]; ll lazy[N<<2]; int getphi(int x) { int res=x; for(int i=2; i<=sqrt(x); i++) { if(x%i==0) { res=res*(i-1)/i; while(x%i==0) x/=i; } } if(x>1) res=res*(x-1)/x; return res; } void pushup(int u) { tr[u].val=(tr[ls].val+tr[rs].val)%mod; } void pushdown(int u) { if(lazy[u]!=1) { lazy[ls]=lazy[u]*lazy[ls]%mod; lazy[rs]=lazy[u]*lazy[rs]%mod; tr[ls].val=tr[ls].val*lazy[u]%mod; tr[rs].val=tr[rs].val*lazy[u]%mod; lazy[u]=1; } } void build(int u,int l,int r) { lazy[u]=1; if(l==r) tr[u]= {l,r,getphi(arr[l])}; else { int mid=l+r>>1; tr[u]= {l,r}; build(ls,l,mid); build(rs,mid+1,r); pushup(u); } } ll query(int u, int l, int r) { if(l<=tr[u].l && tr[u].r<=r) return tr[u].val; pushdown(u); int mid=(tr[u].l+tr[u].r)>>1; ll res=0; if(l<=mid) res=(res+query(ls, l, r))%mod; if(r>mid) res=(res+query(rs, l, r))%mod; return res; } int pr[100],tot; void init() { for(int i=2; i<=100; i++) { int flag=0; for(int j=2; j<=sqrt(i); j++) { if(i%j==0) flag=1; } if(!flag) pr[++tot]=i; } for(int i=1; i<=tot; i++) { for(int j=1; j<=n; j++) { if(arr[j]%pr[i]==0) fa[i][j]=j+1; } } } void mul(int u,int l,int r,int c) { if(tr[u].l>=l && tr[u].r<=r) { lazy[u]=lazy[u]*c%mod; tr[u].val=tr[u].val*c%mod; } else { pushdown(u); int mid=tr[u].l+tr[u].r>>1; if(l<=mid) mul(ls,l,r,c); if(r>mid) mul(rs,l,r,c); pushup(u); } } int find(int c,int x) { if(x==fa[c][x]) return x; return fa[c][x]=find(c,fa[c][x]); } void merge(int l,int r,int c) { int k; for(int i=l; ; i=k+1) { k=find(c,i); if(k>r) { mul(1,i,r,pr[c]); break; } else { if(k>i) mul(1,i,k-1,pr[c]); fa[c][i]=k+1; mul(1,k,k,pr[c]-1); fa[c][k]=k+1; } } } void update(int l,int r,int w) { for(int i=1; i<=25; i++) { while(w%pr[i]==0) { merge(l,r,i); w/=pr[i]; } } } signed main() { ios; cin>>n>>m; for(int i=1; i<=n; i++) { cin>>arr[i]; for(int j=1; j<=25; j++) fa[j][i]=i; } for(int j=1; j<=25; j++) fa[j][n+1]=n+1; init(); build(1,1,n); while(m--) { int op,l,r,w; cin>>op; if(op==0) { cin>>l>>r>>w; update(l,r,w); } else { cin>>l>>r; cout<<query(1,l,r)<<endl; } } return 0; }
|