CF--新年场--C

关键

就很神奇的思路呀
如果两个数%x相等,那么他们加上某个数余x为0后,还是余数相等,并且并不互质,如果%x为任何数的都有两个,那么就肯定不会满足条件。
因为怎么样都会有那种两个人相等的情况。所以,必须满足有一个的余数是小于2的才可以。
我当时是一点也不会,还是彭少想出来的。

代码

#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using pdd=pair<double,double>;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define TT int _=read();while(_--)
#define int long long
using ll=long long;
const ll inf=1e18;
//#define double long double
#define endl '\n'
const int M=1e6+5;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    return x*f;
}

inline void print(int x) {
    if(x<0){putchar('-');x=-x;}
    if(x/10)print(x/10);
    putchar(x%10+'0');
}

int a[M],cnt[100];
//必须要保证每一种的余数,没有全部大于2的
//如果每一种余数都大于2的话,那偏移肯定会有相等的

signed main() {
    TT {
        map<int,int>mp;
        int n=read();
        for(int i=1;i<=n;i++)a[i]=read(),mp[a[i]]++;
        bool flag=1;
        if(mp.size()!=n)flag=0;
        for(int i=2;i<=n;i++) {
            for(int j=1;j<=n;j++)
                cnt[a[j]%i]++;
            bool t=1;
            for(int j=0;j<i;j++) {
                if(cnt[j]<2)t=0;
                cnt[j]=0;
            }
            if(t)flag=0;
        }
        if(flag)cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}
//依次执行
posted @ 2022-12-31 20:26  basicecho  阅读(34)  评论(0)    收藏  举报