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
80
81
82
83
84
85
86
87
88
89
#include<bits/stdc++.h>
using namespace std;

#define int long long
const int N = 100000 + 30;
int tab[N];
int temp[N];
bool sito[N];
void reset(int n) {
    for(int i=0; i<=n; i++) {
        temp[i] = 0;
    }
}

bool check(int k, int n){
    reset(n);
    for(int i=0; i<n; i++) {
        if(i == 0) {
            temp[i] += tab[i];
            temp[i+k] -= tab[i];
            continue;
        }
        if(i + k <= n) {

            int prev = temp[i-1];
            if(temp[i] + prev > tab[i]) return false;
            int diff = tab[i] - prev - temp[i];
            temp[i] = tab[i];
            temp[i+k] -= diff;
        }
        else {
            if(temp[i-1] + temp[i] == tab[i]) {
                temp[i] = tab[i];
            }
            else {
                return false;
            }
        }

    }

    return true;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++) {
        cin>>tab[i];
    }

    int k = 2;
    int last_good = 1;
    while(k <= n) {
        if(sito[k] == true) {
            k++;
            continue;
        }
        if(check(k, n)) {
            last_good = k;
        }
        else {
            int i = k;
            while(i <= n) {
                sito[i] = true;
                i += i;
            }

        }
        k++;
    }
    cout<<last_good;
/*
    while(k-p>1) {
        int mid = (p+k) / 2;
        if(check(mid, n)) {
            p = mid;
        }
        else {
            k = mid;
        }

    }
    if(check(k, n)) cout<< k;
    else cout<<p;*/

}