本题数据过水,对于这个代码:
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int a[N];
int main(){
int n;
cin >> n;
for (int i = 1; i <= n; i ++ ){
cin >> a[i];
}
int t = 0;
for (int i = 1; i <= n; i ++ ){
for (int j = i + 1; j <= n; j ++ ){
t = __gcd(t,abs(a[i] - a[j]));
}
}
for (int i = 2; i <= t; i ++ ){
if (t % i == 0){
cout << i << " ";
}
}
return 0;
}
对于hack数据:
2
1000000000 100000
加上了clock,运行了 1344 毫秒。
实测会TLE,但是能AC,请求添加hack数据。