#include using namespace std; namespace std { // 定数 namespace ns_constant { const long long MOD = 998244353; //const long long MOD = 1000000007; const long long INF = 1LL << 60; const long long xorI = (1LL << 61) - 1; const long long mod = (1LL << 61) - 1; const long long MASK30 = (1LL << 30) - 1; const long long MASK31 = (1LL << 31) - 1; const long double PI = acos(-1); const long double eps = 1e-10; const long long dx[] = { 1, 0,-1, 0, 1,-1, 1,-1 }; const long long dy[] = { 0, 1, 0,-1, 1,-1,-1, 1 }; const pair dxy[] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1} }; } using namespace ns_constant; // 型定義 namespace ns_type_define { template using VT = vector; typedef long long LI; typedef vector
  • VI; typedef vector VVI; typedef vector V3I; typedef vector V4I; typedef long double LD; typedef vector VD; typedef vector VVD; typedef vector VB; typedef vector VVB; typedef vector VC; typedef vector VVC; typedef vector VS; typedef vector VVS; typedef pair PII; typedef vector VPII; typedef vector VVPII; typedef pair PDD; typedef vector VPDD; typedef vector VVPDD; typedef pair PSI; typedef vector VPSI; typedef tuple TI; typedef vector VTI; typedef vector VVTI; typedef tuple TD; typedef vector VTD; typedef vector VVTD; typedef set
  • SI; typedef set SPII; typedef multiset
  • mSI; typedef vector VSI; typedef vector VVSI; typedef map MII; typedef map MPIII; typedef multimap mMII; typedef vector VMII; typedef vector VVMII; typedef map MSI; typedef multimap mMSI; typedef vector VMSI; typedef queue
  • QI; typedef queue QPII; typedef priority_queue> PQPII; //優先順位付きqueue(昇順) template using PQD = priority_queue; template using PQU = priority_queue, greater>; template using PQC = priority_queue, function>; } using namespace ns_type_define; // マクロ namespace ns_macro { // ### 標準 ### namespace ns_macro_std { #define mid(a, b, c) (a < b ? (a < c ? min(b, c) : a) : (b < c ? min(a, c) : b)) #define maxa(a, b) a = max(a, b); #define mina(a, b) a = min(a, b); #define mida(a, b, c) a = mid(a, b, c); #define qpop(u, que) auto u = que.front(); que.pop(); #define qpop2(u, v, que) auto [u, v] = que.front(); que.pop(); #define qpop3(u, v, c, que) auto [u, v, c] = que.front(); que.pop(); #define pqpop(u, que) auto u = que.top(); que.pop(); #define pqpop2(u, v, que) auto [u, v] = que.top(); que.pop(); #define pqpop3(u, v, c, que) auto [u, v, c] = que.top(); que.pop(); #define bits(x) (1LL << (x)) #define minf(x) ((x) != INF ? (x) : -1) } using namespace ns_macro_std; // ### ループ ### namespace ns_macro_loop { // #define REP(i, j, k) for (LI i = j; i < (LI)k; i++) #define DREP(i, j, k) for (LI i = k - 1; i >= (LI)j; i--) #define rep(i, j) for (int i = 0; i < (int)j; i++) #define drep(i, j) for (int i = (int)j - 1, i >= 0, i--) #define repi(i, j) for (int i = 1; i <= (int)j; i++) #define drepi(i, j) for (int i = (int)j; i > 0; i--) #define vrep(a, v) for (auto& a: v) #define vrep2(a, b, v) for (auto& [a, b]: v) #define vrep3(a, b, c, v) for (auto& [a, b, c]: v) #define vrep4(a, b, c, d, v) for (auto& [a, b, c, d]: v) #define vcrep(a, v) for (const auto& a: v) #define vcrep2(a, b, v) for (const auto& [a, b]: v) #define vcrep3(a, b, c, v) for (const auto& [a, b, c]: v) #define vcrep4(a, b, c, d, v) for (const auto& [a, b, c, d]: v) // 集合 bit の部分集合を bit全探索 #define brep(subbit, bit) for (LI subbit = bit; subbit; subbit = (subbit - 1) & bit) // 要素数 R の部分集合を bit全探索 #define bcrep(bit, N, R) for (LI bit = bits(R) - 1, x, y; bit < bits(N); x = bit & -bit, y = bit + x, bit = (((bit & ~y) / x) >> 1) | y) } using namespace ns_macro_loop; // ### 配列操作 ### namespace ns_macro_vector { void vsort(string& v) { sort(v.begin(), v.end()); } template void vsort(vector& v) { sort(v.begin(), v.end()); } void vsortr(string& v) { sort(v.begin(), v.end(), greater()); } template void vsortr(vector& v) { sort(v.begin(), v.end(), greater()); } #define all(v) v.begin(), v.end() #define vmax(v) (*max_element(all(v))) #define vmin(v) (*min_element(all(v))) #define miman(v, a) (lower_bound(all(v), a) - v.begin()) #define ika(v, a) (upper_bound(all(v), a) - v.begin()) #define ijo(v, a) (v.end() - lower_bound(all(v), a)) #define yorio(v, a) (v.end() - upper_bound(all(v), a)) #define iwa(W, A) VI W(1); vrep(a, A) W.push_back(W.back() + a); #define dwa(W, A) VD W(1); vrep(a, A) W.push_back(W.back() + a); #define vsorto(v, compare) sort(all(v), compare); #define vrev(v) reverse(all(v)); #define vcomp(v) v.erase(unique(all(v)), v.end()); #define vuni(v) vsort(v); vcomp(v); } using namespace ns_macro_vector; // ### 入力系 ### namespace ns_macro_input { namespace ns_macro_input_std { #define scan(Type, a) Type a; cin >> a; #define scan2(Type, a, b) scan(Type, a) scan(Type, b) #define scan3(Type, a, b, c) scan(Type, a) scan2(Type, b, c) #define scan4(Type, a, b, c, d) scan(Type, a) scan3(Type, b, c, d) #define vscan(Type, A, N) vector A((int)N); rep(mci, N) { cin >> A[mci]; } #define vscan2(Type, A, B, N) vector A((int)N), B((int)N); rep(mci, N) { cin >> A[mci] >> B[mci]; } #define vscan3(Type, A, B, C, N) vector A((int)N), B((int)N), C((int)N); rep(mci, N) { cin >> A[mci] >> B[mci] >> C[mci]; } #define vscan4(Type, A, B, C, D, N) vector A((int)N), B((int)N), C((int)N), D((int)N); rep(mci, N) { cin >> A[mci] >> B[mci] >> C[mci] >> D[mci]; } #define vvscan(Type, A, H, W) vector A((int)H, vector((int)W)); rep(mch, H) { rep(mcw, W) { cin >> A[(int)mch][(int)mcw]; } } #define pscan(Type1, Type2, a) pair a; cin >> a.first >> a.second; #define pscan2(Type1, Type2, a, b) pscan(Type1, Type2, a) pscan(Type1, Type2, b); #define pscan3(Type1, Type2, a, b, c) pscan(Type1, Type2, a) pscan2(Type1, Type2, b, c); #define pscan4(Type1, Type2, a, b, c, d) pscan(Type1, Type2, a) pscan3(Type1, Type2, b, c, d); #define vpscan(Type1, Type2, A, N) vector> A((int)N); rep(mci, N) { cin >> A[mci].first >> A[mci].second; } #define tscan(Type1, Type2, Type3, a) Type1 mca; Type2 mcb; Type3 mcc; cin >> mca >> mcb >> mcc; tuple a = { mca, mcb, mcc }; #define vtscan(A, N) vector> A((int)N); rep(mci, N) { Type1 mca; Type2 mcb; Type3 mcc; cin >> mca >> mcb >> mcc; A[mci] = { mca, mcb, mcc }; } } using namespace ns_macro_input_std; namespace ns_macro_input_longlong { #define iscan(a) scan(LI, a) #define iscan2(a, b) scan2(LI, a, b) #define iscan3(a, b, c) scan3(LI, a, b, c) #define iscan4(a, b, c, d) scan4(LI, a, b, c, d) #define viscan(A, N) vscan(LI, A, N) #define viscan2(A, B, N) vscan2(LI, A, B, N) #define viscan3(A, B, C, N) vscan3(LI, A, B, C, N) #define viscan4(A, B, C, D, N) vscan4(LI, A, B, C, D, N) #define vviscan(A, H, W) vvscan(LI, A, H, W) #define piscan(a) pscan(LI, LI, a) #define piscan2(a, b) pscan2(LI, LI, a, b) #define piscan3(a, b, c) pscan3(LI, LI, a, b, c) #define piscan4(a, b, c, d) pscan4(LI, LI, a, b, c, d) #define vpiscan(A, N) vpscan(LI, LI, A, N) #define tiscan(a) tscan(LI, LI, LI, a) #define vtiscan(A, N) VTI A((int)N); rep(mci, N) { LI mca, mcb, mcc; cin >> mca >> mcb >> mcc; A[mci] = { mca, mcb, mcc }; } } using namespace ns_macro_input_longlong; namespace ns_macro_input_longlong_decrease { #define iscand(a) iscan(a) a--; #define iscand2(a, b) iscand(a) iscand(b) #define iscand3(a, b, c) iscand(a) iscand2(b, c) #define iscand4(a, b, c, d) iscand(a) iscand3(b, c, d) #define viscand(A, N) viscan(A, N) rep(mci, N) { A[mci]--; } #define viscand2(A, B, N) viscan2(A, B, N) rep(mci, N) { A[mci]--; B[mci]--; } #define viscand3(A, B, C, N) viscan3(A, B, C, N) rep(mci, N) { A[mci]--; B[mci]--; C[mci]--; } #define viscand4(A, B, C, D, N) viscan4(A, B, C, D, N) rep(mci, N) { A[mci]--; B[mci]--; C[mci]--; D[mci]--; } #define vviscand(A, H, W) vviscan(A, H, W) rep(mch, H) { rep(mcw, W) { A[mch][mcw]--; } } #define piscand(a) piscan(a); a.first--; a.second--; #define piscand2(a, b) piscand(a) piscand(b) #define piscand3(a, b, c) piscand(a) piscand2(b, c) #define piscand4(a, b, c, d) piscand(a) piscand3(b, c, d) #define vpiscand(A, N) vpiscan(A, N); rep(mci, N) { A[mci].first--; A[mci].second--; } #define tiscand(a) LI mca, mcb, mcc; cin >> mca >> mcb >> mcc; TI a = { mca, mcb, mcc }; #define vtiscand(A, N) VTI A(N); rep(mci, N) { LI mca, mcb, mcc; cin >> mca >> mcb >> mcc; A[mci] = { mca - 1, mcb - 1, mcc }; } } using namespace ns_macro_input_longlong_decrease; namespace ns_macro_input_longdouble { #define dscan(a) scan(LD, a) #define dscan2(a, b) scan2(LD, a, b) #define dscan3(a, b, c) scan3(LD, a, b, c) #define dscan4(a, b, c, d) scan4(LD, a, b, c, d) #define vdscan(A, N) vscan(LD, A, N) #define vdscan2(A, B, N) vscan2(LD, A, B, N) #define vdscan3(A, B, C, N) vscan3(LD, A, B, C, N) #define vdscan4(A, B, C, D, N) vscan4(LD, A, B, C, D, N) #define vvdscan(A, H, W) vvscan(LD, A, H, W) #define pdscan(a) pscan(LD, LD, a) #define pdscan2(a, b) pscan2(LD, LD, a, b) #define pdscan3(a, b, c) pscan3(LD, LD, a, b, c) #define pdscan4(a, b, c, d) pscan4(LD, LD, a, b, c, d) #define vpdscan(A, N) vpscan(LD, LD, A, N) #define tdscan(a) tscan(LI, LI, LD, a) #define vtdscan(A, N) VTD A(N); rep(mci, N) { LI mca, mcb; LD mcc; cin >> mca >> mcb >> mcc; A[mci] = { mca, mcb, mcc }; } #define tdscand(a) tscand(LI, LI, LD, a) #define vtdscand(A, N) VTD A(N); rep(mci, N) { LI mca, mcb; LD mcc; cin >> mca >> mcb >> mcc; A[mci] = { mca - 1, mcb - 1, mcc }; } } using namespace ns_macro_input_longdouble; namespace ns_macro_input_string { #define sscan(a) scan(string, a) #define sscan2(a, b) scan2(string, a, b) #define sscan3(a, b, c) scan3(string, a, b, c) #define sscan4(a, b, c, d) scan4(string, a, b, c, d) #define vsscan(S, N) vscan(string, S, N) } using namespace ns_macro_input_string; } using namespace ns_macro_input; // ### 出力系 ### namespace ns_macro_output { namespace ns_macro_output_std { #define el cout << endl; #define show(a) cout << (a) << endl; #define show2(a, b) cout << (a) << " " << (b) << endl; #define show3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl; #define show4(a, b, c, d) cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl; #define shown(a) cout << (a) << " "; #define shown2(a, b) cout << (a) << " " << (b) << " "; #define shown3(a, b, c) cout << (a) << " " << (b) << " " << (c) << " "; #define shown4(a, b, c, d) cout << (a) << " " << (b) << " " << (c) << " " << (d) << " "; #define vshow(A) vcrep(a, A) { show(a) } #define vshown(A) vcrep(a, A) { shown(a) } el #define vvshow(A) vcrep(a, A) { vshown(a) } #define pshow(a) show2((a).first, (a).second) #define pshown(a) shown2((a).first, (a).second) #define pshow2(a, b) pshown(a) pshow(b) #define vpshow(A) vcrep(a, A) { pshow(a) } #define tshow(a) show3(get<0>(a), get<1>(a), get<2>(a)) #define tshown(a) shown3(get<0>(a), get<1>(a), get<2>(a)) #define vtshow(A) vcrep(a, A) { tshow(a) } #define showif(f, a, b) if (f) { show(a) } else { show(b) } #define shownif(f, a, b) if (f) { shown(a) } else { shown(b) } #define yes(f) showif(f, "Yes", "No") } using namespace ns_macro_output_std; namespace ns_macro_output_by_type { #define ishow(a) show(minf(a)) #define ishown(a) shown(minf(a)) #define vishow(A) vcrep(a, A) { ishow(a) } #define vishown(A) vcrep(a, A) { ishown(a) } el #define vvishow(A) vcrep(a, A) { vishown(a) } #define dnshow(x, n) cout << fixed << setprecision(n) << (x) << endl; #define dnshown(x, n) cout << fixed << setprecision(n) << (x) << " "; #define vdnshow(A, n) vcrep(a, A) { dshow(a, n) } #define vdnshown(A, n) vcrep(a, A) { dshown(a, n) } el #define vvdnshow(A, n) vcrep(a, A) { vdshown(a, n) } #define dshow(x) cout << fixed << setprecision(10) << (x) << endl; #define dshown(x) cout << fixed << setprecision(10) << (x) << " "; #define vdshow(A) vcrep(a, A) { dshow(a) } #define vdshown(A) vcrep(a, A) { dshown(a) } el #define vvdshow(A) vcrep(a, A) { vdshown(a) } #define bshow(a, n) show(bitset(a)) #define bshown(a, n) shown(bitset(a)) #define vbshow(A, n) vcrep(a, A) { show(bitset(a)) } #define vbshown(A, n) vcrep(a, A) { shown(bitset(a)) } el #define vvbshow(A, n) vcrep(a, A) { vbshow(a, n) } } using namespace ns_macro_output_by_type; namespace ns_macro_output_debug { #define debughead shown(">>") #define debugm(a) shown3(#a, "=", a) #define debugn(a) debugm(a) shown(",") #define debug(a) debughead debugm(a) el #define debug2(a, b) debughead debugn(a) debugm(b) el #define debug3(a, b, c) debughead debugn(a) debugn(b) debugm(c) el #define debug4(a, b, c, d) debughead debugn(a) debugn(b) debugn(c) debugm(d) el } using namespace ns_macro_output_debug; } using namespace ns_macro_output; } using namespace ns_macro; } VI prime(const LI& N) { VI res; for (LI i = 2; i <= N; i++) { bool flg = true; for (LI j = 2; j * j <= i; j++) { if (i % j) continue; flg = false; break; } if (flg) res.push_back(i); } return res; } VI divide(LI N) { VI res; for (LI i = 2; i * i <= N; i++) { if (N % i != 0) continue; res.push_back(i); while (N % i == 0) N /= i; } if (N != 1) res.push_back(N); return res; } // UnionFind template class union_find { private: // 頂点数 int N; // 無限遠の距離 T dinf; // parent[i]:頂点i の親/頂点i が属する木のサイズ(頂点i が根ではない/頂点i が根) vector parent; // dist[i]:親から頂点i までの距離 vector temporarily_distance; // 木の根から頂点i までの距離 T calc_distance(LI i) { root(i); return temporarily_distance[(int)i]; } public: union_find(LI N = 0, T dinf = INF) : N((int)N), dinf(dinf), parent((int)N, -1), temporarily_distance((int)N) {} // 頂点i の根 int root(LI i) { if (parent[(int)i] < 0) return (int)i; int root_index = root(parent[(int)i]); temporarily_distance[(int)i] += temporarily_distance[parent[(int)i]]; return parent[(int)i] = root_index; } // 頂点i が根かの判定(true/false : 頂点i が根/根じゃない) bool ifroot(LI i) { return i == root(i); } // 頂点i が属する木のサイズ int size(LI i) { return -parent[root(i)]; } // 同じ木に属するかの判定(true/false:頂点a と 頂点b が同じ木に属する/属しない) bool same(LI a, LI b) { return root(a) == root(b); } // 辺の追加(from:始点、to:到達点、distance:距離、戻り値=true/false:追加の成功/失敗) bool add_edge(LI from, LI to, T distance = 0) { if (same(from, to)) return false; distance -= calc_distance(to) - calc_distance(from); from = root(from); to = root(to); if (size(from) < size(to)) { swap(from, to); distance = -distance; } parent[(int)from] += parent[(int)to]; parent[(int)to] = (int)from; temporarily_distance[(int)to] = distance; return true; } bool merge(LI from, LI to, T distance = 0) { return add_edge(from, to, distance); } // start から target までの最短距離(到達できない場合はINF) T dist(LI start, LI target) { return same(start, target) ? calc_distance(target) - calc_distance(start) : dinf; } }; LI ipow(const LI& a, const LI& ex, const LI mod = 0) { if (ex <= 0) return 1; LI res = ipow(a, ex / 2, mod); res *= res; if (mod) res %= mod; if (ex & 1) res *= a; if (mod) res %= mod; return res; } int main() { iscan(N); viscan(A, N); auto P = prime(vmax(A)); LI M = P.size(); union_find
  • uf(N + M + 1); rep(i, N) { auto D = divide(A[i]); vrep(d, D) uf.merge(i, N + miman(P, d)); if (D.empty()) uf.merge(i, N + M); } LI one = uf.size(N + M) - 1; SI used; VI X; rep(i, N) { if (used.count(uf.root(i))) continue; used.insert(uf.root(i)); rep(j, M) { if (!uf.same(i, N + j)) continue; X.push_back(P[j]); break; } } LI G = X.size() + one; LI ans = min(G * 2, vmin(X) * (G - 1)); show(ans); }