目录
原题:
You are given an array of nn non-negative integers a1,a2,…,ana1,a2,…,an. You can make the following operation: choose an integer x≥2x≥2 and replace each number of the array by the remainder when dividing that number by xx, that is, for all 1≤i≤n1≤i≤n set aiai to aimodxaimodx.
Determine if it is possible to make all the elements of the array equal by applying the operation zero or more times.
Input
The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases. Description of the test cases follows.
The first line of each test case contains an integer nn (1≤n≤1051≤n≤105) — the length of the array.
The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109) where aiai is the ii-th element of the array.
The sum of nn for all test cases is at most 2⋅1052⋅105.
Output
For each test case, print a line with YES if you can make all elements of the list equal by applying the operation. Otherwise, print NO.
You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as a positive answer).
Example
input
Copy
4 4 2 5 6 8 3 1 1 1 5 4 1 7 0 8 4 5 9 17 5
output
Copy
YES YES NO YES
Note
In the first test case, one can apply the operation with x=3x=3 to obtain the array [2,2,0,2][2,2,0,2], and then apply the operation with x=2x=2 to obtain [0,0,0,0][0,0,0,0].
In the second test case, all numbers are already equal.
In the fourth test case, applying the operation with x=4x=4 results in the array [1,1,1,1][1,1,1,1].
思路:
1,没有1,从大到小,自己对自己取模,直至为零;
2,有1,排序,,任何相邻两个差不为1就可以从大到小,mod(自己-1)最终为1;
3,
代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxj=2e5+100,mod=1e9+7;
int a[maxj];
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int f1=0,f2=0;
for(int i=1;i<=n;++i){
cin>>a[i];
if(a[i]==1)f1=1;
}
sort(a+1,a+1+n);
for(int i=1;i<n;++i){
if(a[i+1]-a[i]==1){
f2=1;
break;
}
}
if(!f1||!f2){
cout<<"yes"<<'\n';
}else{
cout<<"no"<<'\n';
}
}
return 0;
}