-
Notifications
You must be signed in to change notification settings - Fork 411
/
Copy pathC_1618.cpp
73 lines (67 loc) · 1.71 KB
/
C_1618.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define frn(n) for(int i = 0; i<n; i++)
#define frni(n, k) for(int i = k; i<n; i++)
#define vctri vector<int>
#define vctrl vector<ll>
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t; cin>>t;
while(t--){
int n; cin>>n;
vctrl arr(n);
frn(n) cin>>arr[i];
int cnt_1 = 1, cnt_2 = 1;
ll x = arr[0], y = arr[1];
frn(n){
if(i+2<n && arr[i+2]%x == 0)
cnt_1++;
else break;
i++;
}
frni(n, 1){
if(i+2<n && arr[i+2]%y == 0)
cnt_2++;
else break;
i++;
}
// cout<<cnt_1<<' '<<cnt_2<<endl;
if(n == 2){
if(arr[0] != arr[1])
cout<<arr[1]<<endl;
else cout<<0<<endl;
}
else if(n == 3){
if(cnt_1 == 2) cout<<x<<endl;
else cout<<0<<endl;
}
else if(cnt_1 < n/2 || cnt_2 < n/2){
cout<<0<<endl;
}
else if(n%2 == 1){
if(cnt_1 == (n/2)+1 && cnt_2 == n/2)
cout<<y<<endl;
else if(cnt_2 == n/2)
cout<<y<<endl;
else if(cnt_1 == (n/2)+1)
cout<<x<<endl;
}
else if(n%2 == 0){
if(cnt_1 == n/2 && cnt_2 == n/2)
cout<<y<<endl;
else if(cnt_2 == n/2)
cout<<y<<endl;
else if(cnt_1 == n/2)
cout<<x<<endl;
}
else cout<<0<<endl;
}
return 0;
}