题意:
There are N famous competitive programming websites. Ramzi's rating on the ith website is Ai. Ramzi is very experienced, in one contest, he can change his rating on one website to any other value. What is the minimum number of contests that Ramzi must participate in, so that Ziad accepts him as his team mate?
InputThe first line contains one integer T, the number of test cases.
Each test case starts with one line containing three space-separated integers N, X, and Y, the number of famous websites, the required GCD value, and the required LCM value respectively. (1 ≤ N ≤ 105) (1 ≤ X, Y ≤ 109)
The next line contains N space-separated integers Ai, Ramzi's rating on all websites. (1 ≤ Ai ≤ 109)
OutputFor each test case print one line containing one integer, the minimum number of contests Ramzi must participate in so that he can become Ziad's team mate.
If it is impossible for Ziad to accept him as his team mate , print -1.
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 7901
int T,k,N,X,Y,pos[100005];
int ans,anss,tt,wt;
int GCD(int x,int y)
{
if(x%y==0) return y;
return GCD(y,x%y);
}
int main()
{
cin>>T;
wt=-1;
while(T--)
{
k=0;
ans=-1;
tt=0;
anss=-1;
scanf("%d%d%d",&N,&X,&Y);
if(Y%X!=0||(N==1&&(X!=Y))) {
for(int i=1;i<=N;i++)
scanf("%d",&pos[i]);
printf("-1\n");
}
else
{
for(int i=1;i<=N;i++)
{
scanf("%d",&pos[i]);
if((pos[i]%X!=0)||(Y%pos[i]!=0)) {k++;}
else
{
if(ans==-1) ans=Y/pos[i];
else ans=GCD(ans,Y/pos[i]);
if(anss==-1) anss=pos[i];
else
{
anss=GCD(anss,pos[i]);
}
}
}
if(ans!=1) tt++;
if(anss!=X) tt++;
if(N==1&&X==Y&&k==1) printf("1\n");
else if(k>=tt) printf("%d\n",k);
else
{
printf("%d\n",tt<=N?tt:wt);
}
}
}
}