Advertisement
rembocoder

Untitled

Mar 30th, 2023
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int int64_t
  6.  
  7. const int inf = 2e18;
  8. const int mod = 1e9 + 7;
  9.  
  10. const int max_x = 200000 + 1;
  11.  
  12. int32_t main() {
  13.     ios_base::sync_with_stdio(0);
  14.     cin.tie(0); cout.tie(0);
  15.     int n;
  16.     cin >> n;
  17.     vector<vector<int>> powers(max_x);
  18.     for (int i = 0; i < n; i++) {
  19.         int a;
  20.         cin >> a;
  21.         int a_copy = a;
  22.         for (int i = 2; i * i <= a_copy; i++) {
  23.             int p = 0;
  24.             while (a_copy % i == 0) {
  25.                 a_copy /= i;
  26.                 p++;
  27.             }
  28.             if (p > 0) {
  29.                 powers[i].push_back(p);
  30.             }
  31.         }
  32.         if (a_copy > 1) {
  33.             powers[a_copy].push_back(1);
  34.         }
  35.     }
  36.     int res = 1;
  37.     for (int i = 2; i < max_x; i++) {
  38.         if (powers[i].size() <= n - 2) {
  39.             continue;
  40.         }
  41.         if (powers[i].size() == n - 1) {
  42.             powers[i].push_back(0);
  43.         }
  44.         sort(powers[i].begin(), powers[i].end());
  45.         int p = powers[i][1];
  46.         for (int j = 0; j < p; j++) {
  47.             res *= i;
  48.         }
  49.     }
  50.     cout << res << '\n';
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement