https://vjudge.net/problem/CodeForces-573Ahtml
有n個數ai ,你能夠把每一個數任意次×2 或×3 ,問可否最終使得每一個數相等。ios
x2和x3只能改變數的因子2和3的個數,因此本質就是把這些2和3因子所有去掉,再看每一個數是否相等便可。c++
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define ll long long const int N=200005; const int mod=1e9+7; const double eps=1e-8; const double PI = acos(-1.0); #define lowbit(x) (x&(-x)) ll a[N]; int main() { std::ios::sync_with_stdio(false); int n; cin>>n; int flag=0; for(int i=1;i<=n;i++) { cin>>a[i]; while(a[i]%2==0) a[i]/=2; while(a[i]%3==0) a[i]/=3; if(i>1&&a[i]!=a[i-1]) flag=1; } if(flag) cout<<"No"<<endl; else cout<<"Yes"<<endl; return 0; }