fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using int64 = long long;
  4.  
  5. int64 gcd_ll(int64 a, int64 b) {
  6. while (b) { a %= b; std::swap(a, b); }
  7. return a;
  8. }
  9.  
  10. int main() {
  11. ios::sync_with_stdio(false);
  12. cin.tie(nullptr);
  13.  
  14. int T;
  15. if (!(cin >> T)) return 0;
  16. while (T--) {
  17. int N; cin >> N;
  18. vector<int64> a(N);
  19. for (auto &v : a) cin >> v;
  20.  
  21. int64 g = 0;
  22. for (int i = 1; i < N; ++i)
  23. g = gcd_ll(g, std::llabs(a[i] - a[0]));
  24.  
  25. if (g == 0) cout << "INFINITY\n";
  26. else cout << g << '\n';
  27. }
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty