1 solutions

  • 0
    @ 2026-7-29 10:53:05
    /*
     *                                                     __----~~~~~~~~~~~------___
     *                                    .  .   ~~//====......          __--~ ~~
     *                    -.            \_|//     |||\\  ~~~~~~::::... /~
     *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
     *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
     *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
     *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
     *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
     *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
     *           '         ~-|      /|    |-~\~~       __--~~
     *                       |-~~-_/ |    |   ~\_   _-~            /\
     *                            /  \     \__   \/~                \__
     *                        _--~ _/ | .-~~____--~-/                  ~~==.
     *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
     *                                  -_     ~\      ~~---l__i__i__i--~~_/
     *                                  _-~-__   ~)  \--______________--~~
     *                                //.-~~~-~_--~- |-------~~~~~~~~
     *                                       //.-~~~--\
     *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     *
     *                               神兽保佑            永无BUG
     */
    
    /*
     * @Description: I want to be the weakest vegetable in the world!
     * @Author: I.Z.
    */
    #include<bits/stdc++.h>
    using namespace std;
    #define MOD         998244353
    #define speMOD      2933256077ll
    #define int         long long
    #define pii         pair<int,int>
    #define all(v)      v.begin(),v.end()
    #define pb          push_back
    #define REP(i,b,e)  for(int i=(b);i<(int)(e);++i)
    #define over(x)     {cout<<(x)<<endl;return;}
    #define lowbit(x)   ((x)&(-(x)))
    #define cntbit(x)   __builtin_popcount(x)
    #define deal(v)     sort(all(v));v.erase(unique(v.begin(),v.end()),v.end())
    #define lbound(v,x) lower_bound(all(v),x)-v.begin()
    mt19937 sd(random_device{}());
    int qpow(int a,int b,int m=MOD,int res=1){
    	a%=m;
    	while(b>0)res=(b&1)?(res*a%m):(res),a=a*a%m,b>>=1;
    	return res;
    }
    int exgcd(int x,int y,int &a,int &b){
    	if(y==0){
    		a=1;b=0;
    		return x;
    	}
    	int d=exgcd(y,x%y,a,b);
    	int z=b;
    	b=a-b*(x/y);
    	a=z;
    	return d;
    }
    int _x_,_y_;
    inline int inverse(int x,int y=MOD){
    	exgcd(x,y,_x_,_y_);
    	return (_x_+y)%y;
    }
    int fac[2000005],inv[2000005];
    void init(int n){
    	fac[0]=inv[0]=1;
    	REP(i,1,n+1)fac[i]=fac[i-1]*i%MOD;
    	inv[n]=qpow(fac[n],MOD-2);
    	for(int i=n-1;i>=1;--i)inv[i]=inv[i+1]*(i+1)%MOD;
    }
    int binom(int x,int y){
    	return x<y||y<0? 0:fac[x]*inv[y]%MOD*inv[x-y]%MOD;
    }
    int n,q,p;
    int g;
    vector<int>t;
    int solve(int x){
    	int res=p-1;
    	for(auto i:t){
    		while(res%i==0&&qpow(x,res/i,p)==1)res/=i;
    	}
    //	cout<<x<<' '<<(p-1)/res<<endl;
    	return (p-1)/res;
    }
    int a[200005];
    int seg[800005];
    int tag[800005];
    void build(int l,int r,int p){
    	tag[p]=1;
    	if(l==r)return tag[p]=a[l],seg[p]=solve(l==0? a[l]:a[l]*inverse(a[l-1],::p)%(::p)),void();
    	int m=(l+r)>>1;
    	build(l,m,p*2+1);build(m+1,r,p*2+2);
    	seg[p]=__gcd(seg[p*2+1],seg[p*2+2]);
    }
    void upd(int pos,int l,int r,int p){
    	if(l==r){
    		seg[p]=solve(a[l]);
    		return;
    	}
    	int m=(l+r)>>1;
    	if(m>=pos)upd(pos,l,m,p*2+1);
    	else upd(pos,m+1,r,p*2+2);
    	seg[p]=__gcd(seg[p*2+1],seg[p*2+2]);
    }
    void update(int l,int r,int s,int t,int p,int val){
    	if(l<=s&&t<=r){
    		(tag[p]*=val)%=::p;
    		return;
    	}
    	int m=(s+t)>>1;
    	if(m>=l)update(l,r,s,m,p*2+1,val);
    	if(m<r)update(l,r,m+1,t,p*2+2,val);
    }
    int ask(int pos,int l,int r,int p){
    	if(l==r)return tag[p];
    	int m=(l+r)>>1;
    	if(m>=pos)return ask(pos,l,m,p*2+1)*tag[p]%(::p);
    	else return ask(pos,m+1,r,p*2+2)*tag[p]%(::p);
    }
    int query(int l,int r,int s,int t,int p){
    	if(l<=s&&t<=r)return seg[p];
    	int m=(s+t)>>1;
    	if(m>=r)return query(l,r,s,m,p*2+1);
    	if(m<l)return query(l,r,m+1,t,p*2+2);
    	return __gcd(query(l,r,s,m,p*2+1),query(l,r,m+1,t,p*2+2));
    }
    void Main() {
    	cin>>n>>q>>p;
    	int x=p-1;
    	for(int i=2;i*i<=x;++i)if(x%i==0){
    		t.pb(i);
    		while(x%i==0)x/=i;
    	}
    	if(x>1)t.pb(x);
    	g=0;bool F=1;
    	while(F||__gcd(g,p)!=1){
    		F=0;++g;
    		for(auto i:t)if(qpow(g,p/i,p)==1)F=1;
    	}
    //	cerr<<g<<endl;
    	REP(i,0,n)cin>>a[i],a[i]%=p;
    	build(0,n-1,0);
    	for(int i=n-1;i;--i)(a[i]*=inverse(a[i-1],p))%=p;
    	while(q--){
    		int op,l,r,x;
    		cin>>op>>l>>r;--l,--r;
    		if(op==1){
    			cin>>x;
    			update(l,r,0,n-1,0,x);//区间乘
    			(a[l]*=x)%=p;upd(l,0,n-1,0);
    			if(r+1<n)(a[r+1]*=inverse(x,p))%=p,upd(r+1,0,n-1,0);
    		}else{
    			int t=p-1;t=__gcd(t,solve(ask(l,0,n-1,0)));
    			if(l!=r)t=__gcd(t,query(l+1,r,0,n-1,0));
    			cout<<(p-1)/t<<'\n';
    		}
    	}
    }
    void TC() {
        int tc=1;
    	while(tc--){
    		Main();
    		cout.flush();
    	}
    }
    signed main() {
    	freopen("wish.in","r",stdin);
    	freopen("wish.out","w",stdout);
    	return cin.tie(0),cout.tie(0),ios::sync_with_stdio(0),TC(),0;
    }
    /*
    1. CLEAR the arrays (ESPECIALLY multitests)
    2. DELETE useless output
     */
    
    • 1

    Information

    ID
    3069
    Time
    4000ms
    Memory
    128MiB
    Difficulty
    10
    Tags
    (None)
    # Submissions
    1
    Accepted
    1
    Uploaded By