1 //Accepted 208 KB 157 ms 2 //纯暴力 3 //vis数组初始化时要用多少设置多少,不然TLE 4 #include <cstdio> 5 #include <cstring> 6 #include <iostream> 7 using namespace std; 8 const int imax_n = 1000005; 9 int a[imax_n]; 10 bool vis[imax_n]; 11 int n; 12 bool slove(int k) 13 { 14 memset(vis,false,k*sizeof(vis[0])); 15 for (int i=1;i<=n;i++) 16 { 17 int t=a[i]%k; 18 if (vis[t]) return false; 19 vis[t]=true; 20 } 21 return true; 22 } 23 int main() 24 { 25 int T; 26 scanf("%d",&T); 27 for (int t=1;t<=T;t++) 28 { 29 scanf("%d",&n); 30 for (int i=1;i<=n;i++) 31 scanf("%d",&a[i]); 32 int k=n; 33 while (slove(k)==false) k++; 34 printf("%d\n",k); 35 } 36 return 0; 37 }
时间: 2024-09-29 22:06:09