Language: C++

//
// Created by Tetsuya Shiota on 2019-04-13.
//

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector> 
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(e, o) for (auto &&e : o)
#ifdef LOCAL
#define pp(x) cerr << __LINE__ << ' ' << #x << " = " << (x) << endl
#define dump(x)                                                                \
    cerr << __LINE__ << ' ' << #x << " : ";                                      \
    FOR(e, x) cerr << e << ' ';                                                  \
    cerr << endl;
#else
#define pp(x)
#define dump(x)
#endif

using namespace std;

using Int = long long;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int, Int>;

template <typename T> void reverse(vector<T> &v) {
    reverse(v.begin(), v.end());
}
template <typename T> void sort(vector<T> &v) { sort(v.begin(), v.end()); }
template <typename T> void rsort(vector<T> &v) { sort(v.rbegin(), v.rend()); }
template <typename T> T sum(const vector<T> &v) {
    return accumulate(v.begin(), v.end(), T(0));
}
template <class T> void update_max(T &a, const T &b) { a = max(a, b); }
template <class T> void update_min(T &a, const T &b) { a = min(a, b); }
vector<pair<char, Int>> merge_cont_char(const string &s) {
    vector<pair<char, Int>> ret;
    if (s.empty())
        return ret;
    ret.push_back(make_pair(s[0], 0));
    FOR(c, s) {
        if (ret.back().first == c)
            ret.back().second++;
        else
            ret.push_back(make_pair(c, 1));
    }
    return ret;
}

class Shakutori {
    public:
        // 全体の範囲
        // [0, end)
        // 注目している範囲
        // [tail, head)
        Int head, tail, end = 0;
        bool moveHead() {
            if (head == end) {
                return false;
            }
            head++;
            return true;
        }
        void moveTail() { tail++; }
        bool valid() {
            if (head == tail)
                return true;
            // [tail, head)
            // が解として適当か検証する
            return true;
        }
        void solve() {
            head = tail = 0;
            Int ans = 0;
            while (moveHead()) {
                while (!valid()) {
                    moveTail();
                }
                // ここで解を更新する
            }
        }
};

const Int MAX = Int(sqrt(1e9)+100);

vi vprimes;
bool *isPrime = new bool[MAX];

/* 素数生成 O(n^2) */
void MakePrime(){
    for(int i=0;i<MAX;++i)
        isPrime[i]=true;
    isPrime[0]=false;
    isPrime[1]=false;
    for(long long int i=2;i<MAX;++i)
        if(isPrime[i])
            for(long long int j=2;i*j<MAX;++j)
                isPrime[i*j]=false;
    for(int i = 0; i < MAX; ++i)
        if( isPrime[i] )
            vprimes.push_back( i );
}

// 同じ素因数をまとめて、その個数をペアで持つ
void Factorization(Int n, vector< pair<Int,Int> > &vp){
    if(n==1){vp.push_back(make_pair(1,1));return ;}
    for(int i = 0; i < vprimes.size(); ++i){
        while(n%vprimes[i]==0){
            n/=vprimes[i];
            if( vp.size()>0 && vp.back().first == vprimes[i] )
                vp.back().second++;
            else
                vp.push_back( make_pair(vprimes[i],1) );
        }
        if(n==1)return ;
    }
    vp.push_back( make_pair(n,1) );  
}

class Solver {
    public:
        Int N, ans;
        vi A;
        Solver() {}
        void input() {
            cin >> N;
            A = vi(N);
            FOR(a, A)cin >> a;
        }
        void solve() {
            cerr << "solve " <<endl;
            sort(A);
            if(A[0] == A[A.size()-2]){
                ans = A[0];
                return;
            }
            vprimes.clear();
            MakePrime();
            pp(vprimes.size());
            Int lcm = 1, maxi = 1;
            FOR(p, vprimes){
                Int miniA = 1e9, miniB = 1e9;
                FOR(a, A){
                    Int tmp = a;
                    while(tmp % p == 0){
                        tmp /= p;
                    }
                    if(a/tmp < miniA){
                        miniB = miniA;
                        miniA = a/tmp;
                    }else if(a/tmp < miniB){
                        miniB = a/tmp;
                    }
                    a = tmp;
                }
                assert(miniA != 1e9);
                assert(miniB != 1e9);
                lcm *= miniA;
                update_max(maxi, miniB/miniA);
            }
            FOR(a, A)assert(a == 1);
            pp(lcm);
            pp(maxi);
            ans = lcm * maxi;
            /*
               vector<vector<pii>> vps;
               map<Int, vi> DivOfP;
               rep(i, N){
               vector<pii> vp;
               Factorization(A[i], vp);
               FOR(p, vp){
               DivOfP[p.first].push_back(p.second);
               }
               }
               cerr << "fact end" <<endl;
               Int maxiUp = 1, lcm = 1;
               FOR(d, DivOfP){
               vi vp = d.second;
               sort(vp);
               if(vp.size() == 1)continue;
               if(vp.size() < N-1)continue;
               Int a = vp[0], b = vp[1];
               if(vp.size() == N-1){
               a = 0;
               b = vp[0];
               }
               rep(i, a)lcm *= d.first;
               dump(vp);
               if(a != b){
               Int tmp = 1;
               rep(i, b - a){
               tmp *= d.first;
               }
               update_max(tmp, maxiUp);
               }
               }
               pp(lcm);
               pp(maxiUp);
               ans = lcm * maxiUp;
               */
        }
        void output() {
            cout << ans <<endl;
        }
};

void initilization() {
    struct BoolName : numpunct<char> {
        string t, f;
        BoolName(string t = "Yes", string f = "No") : t(t), f(f) {}
        string do_truename() const { return t; }
        string do_falsename() const { return f; }
    };
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
}

int main() {
#ifdef LOCAL
    while (1) {
        Solver s;
        s.input();
        if (cin.eof())
            break;
        s.solve();
        s.output();
    }
#else
    Solver s;
    s.input();
    s.solve();
    s.output();
#endif
}


Compiler output:
a.cc:100:21: error: 'sqrt' was not declared in this scope; did you mean 'sort'?
  100 | const Int MAX = Int(sqrt(1e9)+100);
      |                     ^~~~
      |                     sort
a.cc: In member function 'void Solver::solve()':
a.cc:172:17: error: 'assert' was not declared in this scope
  172 |                 assert(miniA != 1e9);
      |                 ^~~~~~
a.cc:20:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
   19 | #include <unordered_set>
  +++ |+#include <cassert>
   20 | #include <vector>
a.cc:177:22: error: 'assert' was not declared in this scope
  177 |             FOR(a, A)assert(a == 1);
      |                      ^~~~~~
a.cc:177:22: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'