fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int t;
  7. cin >> t;
  8. while (t--)
  9. {
  10. int n;
  11. cin >> n;
  12. int a[n + 123];
  13. for (int i = 1; i <= n; i++)
  14. cin >> a[i];
  15.  
  16. for (int i = 2; i <= n; i++)
  17. a[i] += a[i - 1];
  18.  
  19. int mn = 0, mx = 0, ans = 0;
  20. for (int i = 1; i * i <= n; i++)
  21. {
  22. if (n % i == 0)
  23. {
  24. int l = i;
  25. for (int j = l; j <= n; j += l)
  26. {
  27. int s = a[j] - a[j - l];
  28. // cout << 1 << " " << s << endl;
  29. mn = min(mn, s);
  30. mx = max(mx, s);
  31. }
  32. }
  33. }
  34. ans = mx - mn;
  35. cout << ans << endl;
  36. }
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5280KB
stdin
5
2
1 2
6
10 2 3 6 1 3
4
1000000000 1000000000 1000000000 1000000000
15
60978 82265 78961 56708 39846 31071 4913 4769 29092 91348 64119 72421 98405 222 14294
8
19957 69913 37531 96991 57838 21008 14207 19198
stdout
2
1646755499
2000000000
1646922990
474076