P2651 添加括号III

P2651 添加括号III
无论怎么添加,a2一定是分母,其他的可以是分子,所以最后看看,(a1*a3*..*an)%a2==0即可

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<queue>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<ctime>
 7 #include<cstring>
 8 #define inf 2147483647
 9 #define For(i,a,b) for(register int i=a;i<=b;i++)
10 #define p(a) putchar(a)
11 #define g() getchar()
12 //by war
13 //2017.10.19
14 using namespace std;
15 int t;
16 int n;
17 int x;
18 int g,gg;
19 int a1,a2;
20 bool flag;
21 void in(int &x)
22 {
23     int y=1;
24     char c=g();x=0;
25     while(c<'0'||c>'9')
26     {
27     if(c=='-')
28     y=-1;
29     c=g();
30     }
31     while(c<='9'&&c>='0')x=x*10+c-'0',c=g();
32     x*=y;
33 }
34 void o(int x)
35 {
36     if(x<0)
37     {
38         p('-');
39         x=-x;
40     }
41     if(x>9)o(x/10);
42     p(x%10+'0');
43 }
44 
45 int gcd(int a,int b)
46 {
47     return (b==0?a:gcd(b,a%b));
48 }
49 
50 int main()
51 {
52     in(t);
53     For(i,1,t)
54     {
55         flag=false;
56         in(n);
57         in(a1),in(a2);
58         a2/=gcd(a2,a1);
59         For(j,3,n)
60         {
61         in(x);
62         a2/=gcd(a2,x);
63         }
64          if(a2==1)
65         puts("Yes");
66         else
67         puts("No");
68     }
69      return 0;
70 }
View Code

 

posted @ 2017-10-19 16:55  WeiAR  阅读(240)  评论(0编辑  收藏  举报