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
#include <cstdio>
#include <vector>
using std::vector;

const int M = 101'013;

int a[M], k[M];

bool prime(int n) {
  for (int i = 2; i*i <= n; i++) if(n % i == 0) return false;
  return true;
}

bool check(int n, int x) {
  if (x == 1) return true;
  int f = 0;
  for (int i = 0; i < n; i++) {
    int z = a[i] - f;
    if (z < 0) return false;
    if (i + x-1 >= n && z > 0) return false;
    k[i + x-1] = z;
    f += z;
    if (i >= x-1) f -= k[i];
  }
  return true;
}

bool warto(int n, const vector<int>& p) {
  for (int i = 0; i < p.size(); i++) {
    while(n % p[i] == 0) n/=p[i];
  }
  return n == 1;
}

int main() {
  int n;
  scanf("%d", &n);
  long long s = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    s += a[i];
  }
  vector<int> pp;
  for (int i = 2; i <= n; i++) if(s % i == 0 && prime(i) && check(n, i)) pp.push_back(i);
  for (int i = n; i >= 1; i--) {
    if (s % i ==0 && warto(i, pp) && (prime(i) || check(n, i))) {
      printf("%d\n", i);
      return 0;
    }
  }
  return 0;
}