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 5276KB
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
1 -1
1 2
3
1 -1718050838
1 2
1 3
1 6
1 1
1 3
1 -1718050836
1 9
1 4
1718050847
1 999999979
1 1000000000
1 1000000000
1 1000000000
1 1999999979
1 2000000000
2000000000
1 -1629810062
1 82265
1 78961
1 56708
1 39846
1 31071
1 4913
1 4769
1 29092
1 91348
1 64119
1 72421
1 98405
1 222
1 14294
1 -1629648836
1 127625
1 38774
1 227888
1 112921
1630037950
1 -339554
1 69913
1 37531
1 96991
1 57838
1 21008
1 14207
1 19198
1 -269641
1 134522
1 78846
1 33405
474076