D. Divide and Equalize

题解

我们只需要将每个数拆成质因数相乘的形式,然后对每个质因数累加,最后观察每个质因数出现的次数是不是数组长度的整数倍即可。

code

 

复制代码
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+5;
int a[N];
map<int ,int > map1;
bool ss(int m){
    for (int i=2;i<=sqrt(m)+1;i++){
        if (m%i==0) return false;
    }
    return true;
}
void chai_x(int m){
    int i=2;
    if (ss(m)){
        map1[m]++;
        return;
    }
    while (m!=1){
        if (m%i==0){
            map1[i]++;
            m/=i;
        }
        else i++;
    }
}
int main(){
//    freopen("input.txt","r",stdin);
    int t;
    cin>>t;
    while (t--){
        int n;
        cin>>n;
        for (int i=1,x;i<=n;i++){
            cin>>x;
            if (x==1) continue;
            chai_x(x);
        }
        bool bol=true;
        for (auto it : map1){
            if ((it.second)%n!=0){
                bol=false;
                break;
            }
        }
        if (bol) cout<<"YES\n";
        else cout<<"NO\n";
        map1.clear();
    }
    return 0;
} 
复制代码

 

posted @   黑屿白  阅读(5)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示