思路:
使m从小到大递增并逐一的验证是否满足集合U中任意两个数m取模相等
ACcode:
#include <iostream>
#include <cstdio>
#include <cstring>
#define maxn 100007
using namespace std;
int p[maxn];
int a[maxn];
int main(){
int n,loop,cnt=1;
scanf("%d",&loop);
while(loop--){
memset(a,0,sizeof(a));
scanf("%d",&n);
for(int i=1;i<=n;++i)
scanf("%d",&a[i]);
bool flag=1;
int i;
for(i=1;;++i){
flag=1;
memset(p,0,sizeof(p));
for(int j=1;j<=n;++j){
if(p[a[j]%i]){
flag=0;
break;
}
p[a[j]%i]=1;
}
if(flag)break;
}
printf("%d\n",i);
}
return 0;
}