fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <numeric>
  5. #include <chrono>
  6. #include <string>
  7.  
  8. #define fast \
  9.   ios::sync_with_stdio(false); \
  10.   cin.tie(nullptr); \
  11.   cout.tie(nullptr);
  12.  
  13. #define fi first
  14. #define se second
  15. #define pr pair
  16. #define ll long long
  17. #define ull unsigned long long
  18. #define db double
  19. #define vt vector
  20. #define ln '\n'
  21.  
  22. using namespace std;
  23.  
  24. const string NAME = "test";
  25. const int MAXN = 20;
  26. const ll MOD = 1e9 + 7;
  27. /*-------------------------------------------------------------*/
  28. int main()
  29. {
  30. fast;
  31.  
  32. auto start = chrono::steady_clock::now();
  33.  
  34. int t;
  35. cin >> t;
  36.  
  37. int n;
  38. while(t--) {
  39. cin >> n;
  40. vector<int> a(n);
  41.  
  42. for(int i = 0; i < n; i++) {
  43. cin >> a[i];
  44. }
  45.  
  46. int x = a[0];
  47. int m = a[0];
  48.  
  49. for(int i = 1; i < n; i++) {
  50. x = __gcd(x, a[i]);
  51. m = min(m, a[i]);
  52. }
  53.  
  54. (x == m) ? cout << "YES" : cout << "NO";
  55. cout << ln;
  56. }
  57.  
  58. auto end = chrono::steady_clock::now();
  59. cerr << "Time = " << chrono::duration<double>(end - start).count() << " s\n";
  60. }
Success #stdin #stdout #stderr 0.01s 5280KB
stdin
2
5
1 2 3 4 5
3
6 30 15
stdout
YES
NO
stderr
Time = 2.9334e-05 s