Codeforces Round #318-(C. Bear and Poker)

Source: Internet
Author: User

Codeforces Round #318-(C. Bear and Poker)

Question:

Now there are n people, each holding a [I] card of value, and each person can increase his/her card number by 2 times and by 3 times each time, then you can ask if it is possible to make the number of cards of the end user the same.

Ideas:

Obviously, because all the numbers must be the same in the end, it can only be the same as the largest number, and it can only be obtained by an increase of 2 or 3 times, therefore, we can divide all the numbers by 2 and 3 until they are not exclusive, and then determine whether all the numbers are the same after the division. If they are the same, it means yes, otherwise, it is not possible.

#include
 
  #include
  
   #include
   
    #include
    
     #includeusing namespace std;#define eps 1e-8#define inf 99999999#define maxn 100010typedef __int64 ll;ll a[maxn];int main(){    int n;    ll max1=-1;    scanf(%d,&n);    for(int i=1;i<=n;i++){        scanf(%I64d,&a[i]);    }    bool ff=false;    for(int i=1;i<=n;i++){        ll res=a[i];        while(a[i]%2==0) a[i]=a[i]/2;        while(a[i]%3==0) a[i]=a[i]/3;    }    ll res=a[1];    bool f1=false;    for(int i=2;i<=n;i++){        if(res!=a[i]){            f1=true; break;        }    }    if(f1) printf(No);    else printf(Yes);}/*26 18*/
    
   
  
 

 

At first I thought wrong. I thought it would be wrong if it could be divisible by the largest number and the divisor % 2 = 0 | % 3 = 0, because, in, 10 is composed of 2 and 5, so it is not possible.

 

 

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.