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]; cin >> n;
  8. for (int i = 0; i < n; i++) cin >> a[i];
  9.  
  10. int ans = 0;
  11. for (int i = 0; i < n; i++) {
  12. for (int j = i + 1; j < n; j++) {
  13. int x = a[i], y = a[j];
  14. if (x == y) {
  15. if (x + 1 > ans) ans = x + 1;
  16. } else {
  17. int d = abs(x - y);
  18. for (int k = 1; k <= d; k++) {
  19. if (d % k == 0) {
  20. int x1 = x + (k - x % k) % k;
  21. int y1 = y + (k - y % k) % k;
  22. int a1 = x1, b1 = y1;
  23. while (b1) {
  24. int temp = b1;
  25. b1 = a1 % b1;
  26. a1 = temp;
  27. }
  28. if (a1 > ans) ans = a1;
  29. }
  30. }
  31. }
  32. }
  33. }
  34. cout << ans << "\n";
  35. }
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0.01s 5320KB
stdin
4
2
1 3
5
5 4 3 2 1
3
5 6 7
3
1 11 10
stdout
2
4
2
10