#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;
using i128 = __int128;
namespace rgs = std::ranges;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> a(n + 1);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
i64 sum = std::accumulate(a.begin(), a.end(), 0LL);
for (int i = n; i >= 1; i--) {
a[i] -= a[i - 1];
}
for (int k = n; ; k--) {
if (sum % k) {
continue;
}
bool ok = true;
for (int b = 0; b < k && ok; b++) {
int s = 0;
for (int i = b; i <= n; i += k) {
s += a[i];
if (s < 0) {
ok = false;
break;
}
}
if (s) {
ok = false;
}
}
if (ok) {
std::cout << k << "\n";
return 0;
}
}
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 | #include <bits/stdc++.h> using i64 = long long; using u64 = unsigned long long; using u32 = unsigned; using u128 = unsigned __int128; using i128 = __int128; namespace rgs = std::ranges; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n; std::vector<int> a(n + 1); for (int i = 0; i < n; i++) { std::cin >> a[i]; } i64 sum = std::accumulate(a.begin(), a.end(), 0LL); for (int i = n; i >= 1; i--) { a[i] -= a[i - 1]; } for (int k = n; ; k--) { if (sum % k) { continue; } bool ok = true; for (int b = 0; b < k && ok; b++) { int s = 0; for (int i = b; i <= n; i += k) { s += a[i]; if (s < 0) { ok = false; break; } } if (s) { ok = false; } } if (ok) { std::cout << k << "\n"; return 0; } } return 0; } |
English