Skip to content

Commit ca3aba3

Browse files
Add files via upload
1 parent b12703f commit ca3aba3

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#pragma GCC optimize("Ofast")
2+
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
3+
#pragma GCC optimize("unroll-loops")
4+
#include <bits/stdc++.h>
5+
using namespace std;
6+
7+
typedef long long ll;
8+
typedef vector<int> vi;
9+
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
10+
11+
12+
int main(){
13+
int t;
14+
cin >> t;
15+
while (t--){
16+
int n, a, b;
17+
cin >> n >> a >> b;
18+
vector<int> v(n);
19+
for (int i = 0; i < n; i++){
20+
cin >> v[i];
21+
}
22+
23+
int d = gcd(a, b);
24+
set<int> s;
25+
for (int i = 0; i < n; i++){
26+
s.insert(v[i]%d);
27+
}
28+
29+
if (s.size() == 0){
30+
cout << 0 << endl;
31+
continue;
32+
}
33+
34+
int biggestGap = *s.begin() + (d - 1 - *s.rbegin());
35+
for (auto it = s.begin(); it != --s.end(); it++){
36+
biggestGap = max(biggestGap, *next(it) - 1 - *it);
37+
}
38+
39+
cout << d - 1 - biggestGap << endl;
40+
41+
}
42+
43+
return 0;
44+
}

0 commit comments

Comments
 (0)