#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include using namespace std; typedef long long ll; #define rep(i,a,n) for (int i=a;i=a;i--) #define pb push_back #define mp make_pair #define SZ(x) ((int)(x).size()) // namespace Factor by Yuhao Du. many thanks! typedef pair PLL; namespace Factor { const int N=1010000; ll C,fac[10010],n,mut,a[1001000]; int T,cnt,i,l,prime[N],p[N],psize,_cnt; ll _e[100],_pr[100]; vector d; inline ll mul(ll a,ll b,ll p) { if (p<=1000000000) return a*b%p; else if (p<=1000000000000ll) return (((a*(b>>20)%p)<<20)+(a*(b&((1<<20)-1))))%p; else { ll d=(ll)floor(a*(long double)b/p+0.5); ll ret=(a*b-d*p)%p; if (ret<0) ret+=p; return ret; } } void prime_table(){ int i,j,tot,t1; for (i=1;i<=psize;i++) p[i]=i; for (i=2,tot=0;i<=psize;i++){ if (p[i]==i) prime[++tot]=i; for (j=1;j<=tot && (t1=prime[j]*i)<=psize;j++){ p[t1]=prime[j]; if (i%prime[j]==0) break; } } } void init(int ps) { psize=ps; prime_table(); } ll powl(ll a,ll n,ll p) { ll ans=1; for (;n;n>>=1) { if (n&1) ans=mul(ans,a,p); a=mul(a,a,p); } return ans; } bool witness(ll a,ll n) { int t=0; ll u=n-1; for (;~u&1;u>>=1) t++; ll x=powl(a,u,n),_x=0; for (;t;t--) { _x=mul(x,x,n); if (_x==1 && x!=1 && x!=n-1) return 1; x=_x; } return _x!=1; } bool miller(ll n) { if (n<2) return 0; if (n<=psize) return p[n]==n; if (~n&1) return 0; for (int j=0;j<=7;j++) if (witness(rand()%(n-1)+1,n)) return 0; return 1; } ll gcd(ll a,ll b) { ll ret=1; while (a!=0) { if ((~a&1) && (~b&1)) ret<<=1,a>>=1,b>>=1; else if (~a&1) a>>=1; else if (~b&1) b>>=1; else { if (a getd() { d.clear(); dfs(1,0); return d; } vector factor(ll n) { cnt=0; _factor(n); norm(); return getd(); } vector factorG(ll n) { cnt=0; _factor(n); norm(); vector d; rep(i,0,_cnt) d.pb(mp(_pr[i],_e[i])); return d; } bool is_primitive(ll a,ll p) { assert(miller(p)); vector D=factorG(p-1); rep(i,0,SZ(D)) if (powl(a,(p-1)/D[i].first,p)==1) return 0; return 1; } } map cache; ll solve(ll x) { if (cache.count(x)) return cache[x]; ll ret = x; Factor::cnt = 0; auto mda = Factor::factor(x); for (auto tt:mda) { if(tt>1) ret = max(ret, tt*solve(x/tt)); if(tt > n; ll ans = 0; while (n--) { ll x; cin >> x; ans += solve(x); } cout << ans << "\n"; return 0; }