fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27.  
  28. vector<int> spf;
  29.  
  30. void seive(){
  31. spf.assign(N+1, 0);
  32. for(int i=2; i<=N; i++) spf[i] = i;
  33. for(int i=2; i*i<=N; i++){
  34. if(spf[i] != i) continue;
  35. for(int j=i*i; j<=N; j+=i){
  36. spf[j] = min(spf[j], i);
  37. }
  38. }
  39. }
  40.  
  41. vector<int> a;
  42.  
  43. int consistency(int n){
  44.  
  45. //* p -> {x, y} , where x and y are 2 mini powers of prime p
  46. unordered_map<int,vector<int>> minPowers;
  47. unordered_map<int,int> freq;
  48. for(int i=0; i<n; i++){
  49. int val = a[i];
  50.  
  51. while(val>1){
  52. int p = spf[val];
  53. int e = 0;
  54.  
  55. while(val%p == 0){
  56. e++;
  57. val /= p;
  58. }
  59. freq[p]++;
  60. minPowers[p].push_back(e);
  61. sort(begin(minPowers[p]), end(minPowers[p]));
  62. if(minPowers[p].size() > 3) minPowers[p].pop_back();
  63. }
  64.  
  65. }
  66.  
  67. int ans = 1;
  68. for(auto& q : minPowers){
  69. int p = q.first;
  70. auto exp = q.second;
  71.  
  72. int e = 0;
  73.  
  74. if(freq[p] == n) e = max(exp[0], exp[1]);
  75. else if(freq[p] == n-1) e = exp[0];
  76.  
  77. if(e!=0){
  78. ans *= pow(p, e);
  79. }
  80. }
  81.  
  82. return ans;
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. int practice(int n){
  100.  
  101.  
  102. return 0;
  103. }
  104.  
  105.  
  106.  
  107.  
  108.  
  109. void solve() {
  110.  
  111. static int _ = (seive(), 0);
  112.  
  113. int n;
  114. cin>> n;
  115.  
  116. a.resize(n);
  117. for(int i=0; i<n; i++) cin >> a[i];
  118.  
  119. cout << consistency(n) << endl;
  120.  
  121.  
  122. }
  123.  
  124.  
  125.  
  126.  
  127.  
  128. int32_t main() {
  129. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  130.  
  131. int t = 1;
  132. // cin >> t;
  133. while (t--) {
  134. solve();
  135. }
  136.  
  137. return 0;
  138. }
Success #stdin #stdout 0.01s 5532KB
stdin
10
540 648 810 648 720 540 594 864 972 648
stdout
54