x2一定是分母。只要x1*x3*....*xk整除x2就可以。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 10050 using namespace std; int t,n,x[maxn]; int gcd(int a,int b) { if (b==0) return a; return gcd(b,a%b); } void work() { scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&x[i]); for (int i=1;i<=n;i++) { if (i==2) continue; x[2]/=gcd(x[i],x[2]); } if (x[2]!=1) printf("NO\n"); else printf("YES\n"); } int main() { scanf("%d",&t); for (int i=1;i<=t;i++) work(); return 0; }