rt,WA test#4,错误信息:https://codeforces.com/problemset/submission/1902/237223869
代码:
# include <bits/stdc++.h>
# define ffor(i,name) \
for (auto i = name.begin (); i != name.end (); i ++)
typedef long long ll;
using namespace std;
int t, n, a[100005], maxx, g, x;
ll sum;
map <int, int> vis;
int main () {
ios::sync_with_stdio (0);
cin.tie (0);
cout.tie (0);
cin >> t;
while (t --) {
sum = 0, maxx = -1e9, vis.clear ();
cin >> n;
for (int i = 0; i < n; ++ i) {
cin >> a[i];
vis[a[i]] = 1;
maxx = max (maxx, a[i]);
}
if (n < 2) {
cout << "1\n";
continue ;
}
g = abs (a[1] - a[0]);
for (int i = 2; i < n; ++ i)
g = __gcd (g, abs (a[i] - a[i - 1]));
for (int i = 0; i < n; ++ i)
sum += (maxx - a[i]) / g;
x = maxx;
while (vis[x])
x -= g, ++ sum;
cout << sum << '\n';
}
return 0;
}