Question 1385: [baltic2000] division expressiontime limit: 5 sec memory limit: 64 MB
The description division expression is in the following format: x1/x2/x3... /XK where Xi is a positive integer and the Division expression xi <= 1000000000 (1 <= I <= K, k <= 10000) should be calculated from left to right, for example, the value of expression 1/2/1/2 is 1/4. however, you can change the calculation order by entering brackets in the expression. For example, the value of (1/2)/(1/2) is 1. A division expression e is provided to indicate whether to add parentheses to enable it as e '. e' is an integer input, and a number D is given first, which indicates that there is a group of D data. each group of data is given a number N, which indicates that there will be n numbers in this group of data. Next, there are n numbers output. If the expression value can be an integer, yes is output. Otherwise, it is nosample input2.
4
1
2
1
2
3
1
2
3 sample outputyes
No question
We can know that X2 is a denominator in any case, and other numbers can be converted into molecules through parentheses, so we can keep Division. It is very spicy to know that X2 is 1!
Code
1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 int gcd(int a,int b){return b==0?a:gcd(b,a%b);} 5 int T,t,n,a[100001]; 6 int main(){ 7 scanf("%d",&T); 8 while(T--){ 9 scanf("%d%d%d",&n,&a[1],&t);10 for(int i=1;i<=n-2;i++)11 scanf("%d",&a[i+1]);12 for(int i=1;i<n;i++){13 t/=gcd(t,a[i]);14 if(t==1){printf("YES\n");break;} 15 } 16 if(t!=1)printf("NO\n");17 }18 return 0;19 }
View code
Bzoj 1385: [baltic2000] division expression