-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcp105.cpp
49 lines (42 loc) · 970 Bytes
/
cp105.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
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
int n;
cin >> n;
long long a[n];
for(int i=0; i<n ;i++){
cin >> a[i];
}
long long val1 =0, val2 =0;
for(int i=0; i<n; i+=2){
val1 = __gcd(val1, a[i]);
}
for(int i=1; i<n; i+=2){
val2 = __gcd(val2, a[i]);
}
bool ispossible1 = true, ispossible2= true;
for(int i=0; i<n; i+=2){
if(a[i] % val2 == 0){
ispossible1 = false;
}
}
for(int i=1; i<n; i+=2){
if(a[i] % val1 == 0){
ispossible2 = false;
}
}
if(!ispossible1 && !ispossible2){
cout << 0 << endl;
}
else if(!ispossible2){
cout << val2 << endl;
}
else{
cout << val1 << endl;
}
}
return 0;
}