Bzoj 1385: [baltic2000] division expression

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.