Codeforces 1401C - Mere Array Solution


  

Solution in C++: 

///******Bismillahir-Rahmanir-Rahim******///

///AH Tonmoy

///Department of CSE,23rd batch

    ///Islamic University,Bangladesh

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        long long  t,n,mn,i,f;
        cin>>t;
        while(t--)
        {
            mn=1000000000,f=0;
            cin>>n;
            long long  a[n+1],b[n+1];
            for(i=0; i<n; i++)
            {
                cin>>a[i];
                mn=min(mn,a[i]);
                b[i]=a[i];
            }
            sort(b,b+n);
            for(i=0; i<n; i++)
            {
                if((a[i]!=b[i])&&(a[i]%mn>0))
                {
                    f=1;
                    break;
                }
            }
            if(f==0)
            cout<<"YES"<<"\n";
            else
            cout<<"NO"<<"\n";
        }
        return 0;
    }
     

    No comments

    Most View Post

    Recent post

    Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

        Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

    Powered by Blogger.