Multiplication are within 150, the decomposition of factorization found only 35, the establishment of 35 tree-like array/line tree, do interval plus, interval query, finally power up quickly.
#include <cstdio> #include <cstring>using namespace std; #define N 50001typedef Long Long ll;ll Quick_pow (ll A, ll P,ll MOD) {if (!p) return 1; ll Ans=quick_pow (A,P>>1,MOD); Ans=ans*ans%mod; if ((p&1) ==1) Ans=ans*a%mod; return ans;} int zu,n,m;int prime[151],en,zyz[151][40];bool vis[151];struct bit{ll d[n];void add_node (int p,const ll &v) {for (;p & lt;=n;p+= (p& (-P))) D[p]+=v;} ll query (int p) {ll res=0;for (;p; p-= (p& (P))) Res+=d[p];return Res;} void Clear () {memset (d,0,sizeof (d));}} T[40];struct bit2{ll d[n];void add_node (int p,const ll &v) {for (;p <=n;p+= (-P)) p&;} void Add_range (const int &l,const int &r,const ll &v) {Add_node (l,v), if (r!=n) Add_node (r+1,-v);} ll query (int p) {ll res=0;for (;p; p-= (p& (P))) Res+=d[p];return Res;} void Clear () {memset (d,0,sizeof (d));}} T2[40];void Shai () {vis[1]=1; for (int i=2;i<=150;i++) {if (!vis[i]) prime[++en]=i; for (int j=i*i;j<=150;j+=i) vis[j]=1; }}voID Add (const int &WH,CONST int &p,const int &v) {T[wh].add_node (P, LL) v* (LL) p); if (p!=1) T2[wh].add_range (1, P-1, (ll) v);} void Add (const int &WH,CONST int &L,CONST int &r,const int &v) {Add (wh,r,v); if (l!=1) Add (Wh,l-1, (LL) (-V)) ;} ll query (const int &WH,CONST int &p) {return t[wh].query (P) +t2[wh].query (P) * (LL) p;} ll query (const int &WH,CONST int &l,const int &r) {return Query (wh,r)-(L==1?0:query (WH,L-1));} ll query (const int &WH,CONST int &l,const int &r) {if (l<=r) return query (WH,L,R); else return query (wh,l,n) + Query (wh,1,r);} int main () {int op,x,y,v; Shai (); for (int i=1;i<=150;++i) {int t=i; for (int j=1;j<=en;++j) while (t%prime[j]==0) {t/=prime[j]; ++ZYZ[I][J]; }}scanf ("%d", &zu), for (; zu;--zu) {for (int i=1;i<=en;++i) {t[i].clear (); T2[i].clear (); } scanf ("%d%d", &n,&m); for (; m;--m) {scanf ("%d%d%d%d", &op,&x,&y,&v); if (op==1) { for (int i=1;i<=en;++i) if (Zyz[v][i]) {if (x<=y) Add (I,x,y,zyz[v][i]); else {ADD (i,x,n,zyz[v][i]); ADD (I,1,y,zyz[v][i]); }}} and else if (op==2) {for (int i=1;i<=en;++i) if (Zyz[v][i]) {if ( x<=y) Add (I,x,y,-zyz[v][i]); else {ADD (i,x,n,-zyz[v][i]); ADD (I,1,y,-zyz[v][i]); }}}} else {ll ans=1; for (int i=1;i<=en;++i) ans= (Ans*quick_pow (LL) prime[i],query (I,x,y), (LL) v))% (ll) v; printf ("%i64d\n", ans); }}}return 0;}
Decomposition factorization "tree array" "Fast power" codeforces ACM-ICPC Vietnam National Second Round E. ACM