题目
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define lson p << 1
#define rson p << 1 | 1
const int maxn = 1e6 + 5, inf = 1e9, maxm = 4e4 + 5;
const int N = 1e6;
const int mod = 1e9 + 7;
// const int mod = 998244353;
//const __int128 mod = 212370440130137957LL;
// int a[505][5005];
// bool vis[505][505];
int a[maxn], b[maxn];
bool vis[maxn];
string s;
int n, m;
struct Node{
int val, id;
bool operator<(const Node &u)const{
return val < u.val;
}
};
// Node c[maxn];
struct Rat{
__int128 a, b;
bool operator<(const Rat &u)const{
return a * u.b < u.a * b;
}
Rat operator*(const Rat &u)const{
__int128 up = a * u.a, down = b * u.b;
__int128 g = __gcd(up, down);
up /= g, down /= g;
return Rat({up, down});
}
};
int ans[maxn];
int pre[maxn];
__int128 qpow(__int128 a, __int128 b){
__int128 res = 1;
while(b){
if(b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
vector<Rat> S;
int calc(__int128 u, __int128 d){
int cnt = 0;
for(auto [a, b] : S){
bool flag = 0;
for(int i = 1; i <= 63; i++){
if(qpow(u, i) > a || qpow(d, i) > b){
return inf;
}
// cout << (int)qpow(u, i) << ' ' << (int)a << ' ' << (int)qpow(d, i) << ' ' << (int)b << '\n';
if(qpow(u, i) == a && qpow(d, i) == b){
flag = 1;
cnt += i - 1;
break;
}
}
if(!flag){
return inf;
}
}
return cnt;
}
//long long ? maxn ?
void solve(){
int res = 0;
// int q, k;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
sort(a + 1, a + n + 1);
if(a[1] == a[n]){
cout << n << '\n';
return;
}
n = unique(a + 1, a + n + 1) - a - 1;
for(int i = 2; i <= n; i++){
int g = __gcd(a[i], a[i - 1]);
Rat u = {a[i] / g, a[i - 1] / g};
S.pb(u);
}
res = inf;
sort(S.begin(), S.end());
__int128 gu = S.begin() -> a, gd = S.begin() -> b;
int tmp;
for(int i = 1; i <= 63; i++){
__int128 u = pow(gu, 1.0 / i) + 0.5;//加0.5,四舍五入才能过!!!!!!!!!!!!!!!
__int128 d = pow(gd, 1.0 / i) + 0.5;
if(qpow(u, i) != gu || qpow(d, i) != gd){
continue;
}
tmp = calc(u, d);
res = min(res, tmp + n);
}
cout << res << '\n';
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
// cin >> T;
while (T--)
{
solve();
}
return 0;
}