[bzoj1385]Division expression
容易发现a2一定是分母,且容易做到其余都是分子,因此相当于判定a2能否整除a1*a3*……*an,不断让a2除以其与其他数的gcd即可(注意特判n=1)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<bits/stdc++.h> 2 using namespace std; 3 int t,n,s,x; 4 int gcd(int x,int y){ 5 if (!y)return x; 6 return gcd(y,x%y); 7 } 8 int main(){ 9 scanf("%d",&t); 10 while (t--){ 11 scanf("%d%d",&n,&x); 12 if (n==1){ 13 printf("YES\n"); 14 continue; 15 } 16 scanf("%d",&s); 17 s/=gcd(s,x); 18 for(int i=3;i<=n;i++){ 19 scanf("%d",&x); 20 s/=gcd(s,x); 21 } 22 if (s==1)printf("YES\n"); 23 else printf("NO\n"); 24 } 25 }