#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, suma;
ll t[100000];
ll t2[100000];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> t[i];
suma += t[i];
}
for (ll i = n; i > 1; i--)
{
if (suma % i != 0) continue;
//cout << '\n' << i << ':';
ll curr = 0;
bool ok = true;
for (int j = 0; j < n; j++)
{
if (j >= i) curr -= t2[j-i];
t2[j] = t[j] - curr;
if (t2[j] < 0 || t2[j] > 0 && n-j < i)
{
ok = false;
break;
}
curr = t[j];
//cout << t2[j] << ' ';
}
if (!ok) continue;
cout << i;
return 0;
}
cout << '1';
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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, suma; ll t[100000]; ll t2[100000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) { cin >> t[i]; suma += t[i]; } for (ll i = n; i > 1; i--) { if (suma % i != 0) continue; //cout << '\n' << i << ':'; ll curr = 0; bool ok = true; for (int j = 0; j < n; j++) { if (j >= i) curr -= t2[j-i]; t2[j] = t[j] - curr; if (t2[j] < 0 || t2[j] > 0 && n-j < i) { ok = false; break; } curr = t[j]; //cout << t2[j] << ' '; } if (!ok) continue; cout << i; return 0; } cout << '1'; return 0; } |
English