-
Notifications
You must be signed in to change notification settings - Fork 4
/
BCSEQ1.cpp
79 lines (77 loc) · 1.5 KB
/
BCSEQ1.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
74
75
76
77
78
79
/*
* =====================================================================================
*
* Filename: test8.cpp
*
* Description:
*
* Version: 1.0
* Created: 11/09/2019 10:41:59
* Revision: none
* Compiler: gcc
*
* Author: hoaf13 (paxd), gam.nhosmiles2000@gmail.com
* Company: Posts and Telecommunications Institute of Technology
*
* =====================================================================================
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void process(){
ll stt;
ll n;
cin >> stt >> n;
ll sumz = 0;
vector<ll>a;
vector<int>uoc;
a.resize(n+1);
vector<ll> dp;
dp.resize(n+1,0);
for(int i=1;i<=n;i++) cin >> a[i],sumz += a[i];
dp[1] = a[1];
for(int i=2;i<=n;i++) dp[i] = dp[i-1] + a[i];
int k = sqrt(sumz);
if (k*k == sumz) uoc.push_back(k);
for(int i=1;i<=k;i++){
if (sumz % i == 0){
uoc.push_back(i);
uoc.push_back(sumz / i);
}
}
sort(uoc.begin(),uoc.end());
for(int i=0;i<uoc.size();i++){
// cout << "uoc: " << uoc[i] << endl;
int indez = 0;
int cnt = 0;
for(int j=1;j<=n;j++){
if (dp[j] - dp[indez] > uoc[i]) break;
if (dp[j] - dp[indez] == uoc[i]){
cnt += (j - indez);
indez = j;
}
}
if (cnt == n){
cout << stt << " " << uoc[i] << endl;
return ;
}
}
}
int main(){
int T;
cin >> T;
while(T--){
process();
}
return 0;
}