这题卡常?
查看原帖
这题卡常?
763878
Jerry_heng楼主2024/11/29 21:11

O(n×p)O(n\times p) 会 T ?

//2024-11-29 20:56:30
#include<bits/stdc++.h>
#define db double
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mkp make_pair
#define pii pair<int,int>
#define int long long
using namespace std;
bool MBE;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f; 
}
int a[1010];
int n,x,y,md;
signed main(){
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    n=read(),x=read(),y=read(),md=read();
    for(int i=1;i<=n;i++){
    	int v=read(),las=v;
    	int cnt=0;
    	while(++cnt){
    		if(cnt>md+5)break;
    		v=(v*x+y)%md;
    		if(v==las){
    			a[cnt]++;
    			break;
    		}
    	}
    }
    int q=read();
    while(q--){
    	int v=read(),ans=0;
    	for(int i=1;i*i<=v&&i<=md;i++){
    		if(v%i)continue;
    		ans+=a[i];
    		if(v/i<=md&&i*i!=v)ans+=a[v/i];
    	}
    	printf("%lld\n",ans);
    }
    bool MED;
    cerr<<(&MED-&MBE)/1048576.0<<" MB, "<<1000*clock()/CLOCKS_PER_SEC<<" ms\n";
    return 0;
}
2024/11/29 21:11
加载中...