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.