fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(0);
  7.  
  8. int n;
  9. cin >> n;
  10. const int MAXA = 1e6;
  11. vector<int> cnt(MAXA+1, 0);
  12.  
  13. for(int i = 0; i < n; i++){
  14. int x;
  15. cin >> x;
  16. cnt[x]++;
  17. }
  18.  
  19. // duyệt từ giá trị lớn nhất xuống
  20. for(int g = MAXA; g >= 1; g--){
  21. int c = 0;
  22. for(int multiple = g; multiple <= MAXA; multiple += g){
  23. c += cnt[multiple];
  24. }
  25. if(c >= 2){
  26. cout << g;
  27. return 0;
  28. }
  29. }
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0.03s 6976KB
stdin
5
3 14 15 7 9
stdout
7