DEV Community

Will Chang
Will Chang

Posted on

Codeforces Round 929 (Div. 3) D. Turtle Tenacity: Continual Mods

/*
by looking at the test cases, I discovered that 
if we divide the array numbers by the gcd of the
whole array(we call this array A), if there are 
more than one 1's in it, then "NO", or else "YES"
pf. just write the array in increasing order and
 it is obvious

*/
#include<bits/stdc++.h>
using namespace std;
int arr[100005]={0};
int main(){
    int t; cin>>t;
    for (int tt=0; tt!=t; tt++){
        for (int i=0; i!=100005; i++){
            arr[i] = 0;
        }
        int n; cin>>n;
        int x; cin>>x;
        int g = x;
        arr[0]=x;
        for (int i=1; i!=n; i++){
            int num; cin>>num;
            arr[i] = num;
            g = __gcd(num,g);
        }
        for (int i=0; i!=n; i++){
            arr[i] = arr[i]/g;          
        }
        int ok = 0;
        for (auto u:arr){
            if (u==1){
                ok += 1;
            }
        }
        //cout<<g<<"\n";
        if (ok>1){
            cout<<"NO"<<"\n";
        }
        else{
            cout<<"YES"<<"\n";
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)