#include <bits/stdc++.h>
#define N 1000311
using namespace std;
int n;
long long k;
int a[N];
int cnt[N];
int d;
int curr;
int w;
vector<int> divs;
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
k += a[i];
}
for (int i = 1; i * i <= k && i <= n; i++) {
if (k % i == 0) {
divs.push_back(i);
if (k / i <= n) {
divs.push_back(k / i);
}
}
}
sort(divs.begin(), divs.end());
w = 1;
for (int j = (int)divs.size() - 1; j > 0; j--) {
curr = 0;
d = divs[j];
for (int i = 0; i < n; i++) {
if (i >= d) {
curr -= cnt[i - d];
}
if (a[i] < curr || (i >= n - d + 1 && a[i] != curr)) {
goto end;
}
if (i < n - d + 1) {
cnt[i] = a[i] - curr;
curr += cnt[i];
}
}
cout << d << "\n";
return 0;
end: ;
}
cout << w << "\n";
return 0;
}
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 | #include <bits/stdc++.h> #define N 1000311 using namespace std; int n; long long k; int a[N]; int cnt[N]; int d; int curr; int w; vector<int> divs; int main() { ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; k += a[i]; } for (int i = 1; i * i <= k && i <= n; i++) { if (k % i == 0) { divs.push_back(i); if (k / i <= n) { divs.push_back(k / i); } } } sort(divs.begin(), divs.end()); w = 1; for (int j = (int)divs.size() - 1; j > 0; j--) { curr = 0; d = divs[j]; for (int i = 0; i < n; i++) { if (i >= d) { curr -= cnt[i - d]; } if (a[i] < curr || (i >= n - d + 1 && a[i] != curr)) { goto end; } if (i < n - d + 1) { cnt[i] = a[i] - curr; curr += cnt[i]; } } cout << d << "\n"; return 0; end: ; } cout << w << "\n"; return 0; } |
English