-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_GCD_Partition.cpp
More file actions
45 lines (39 loc) · 928 Bytes
/
Copy pathB_GCD_Partition.cpp
File metadata and controls
45 lines (39 loc) · 928 Bytes
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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ll long long
ll gcd(ll a , ll b){
if(b==0) return a;
return gcd(b , a%b);
}
int main() {
fastio;
int t;
cin >> t;
while (t--) {
ll n;
cin>>n;
vector<ll> arr(n+1 , 0);
for(ll i=1;i<=n;i++){
cin>>arr[i];
arr[i]+=arr[i-1];
}
//cout<<gcd(2 , 4)<<" ";
int x = 0;
ll sum = arr[n];
ll ans = 1;
//cout<<sum<<" ";
for(ll i=1;i<n;i++){
// cout<<arr[i]<<" "<<sum - arr[i]<<endl;
ans = max(ans , gcd(arr[i] , sum - arr[i]));
// cout<<ans<<":"<<endl;
}
cout<<ans<<endl;
}
return 0;
}