fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t; cin >> t;
  6. while (t--) {
  7. int n, a[100], res = 0;
  8. cin >> n;
  9. for (int i = 0; i < n; i++) cin >> a[i];
  10. for (int i = 0; i < n; i++) {
  11. for (int j = i + 1; j < n; j++) {
  12. int x = a[i], y = a[j], d = abs(x - y);
  13. if (x == y) res = max(res, x + 1);
  14. for (int k = 1; k <= d; k++) {
  15. if (d % k == 0) {
  16. int g1 = x + (k - x % k) % k;
  17. int g2 = y + (k - y % k) % k;
  18. while (g2) {
  19. int tmp = g2;
  20. g2 = g1 % g2;
  21. g1 = tmp;
  22. }
  23. res = max(res, g1);
  24. }
  25. }
  26. }
  27. }
  28. cout << res << "\n";
  29. }
  30. }
  31.  
Success #stdin #stdout 0s 5316KB
stdin
4
2
1 3
5
5 4 3 2 1
3
5 6 7
3
1 11 10
stdout
2
4
2
10