#include <bits/stdc++.h>
#define INF 1000000000
#define M 1000000007
#define ll long long
#define MAX 10000001
using namespace std;
int a[MAX],m[MAX];
int par[MAX],rank[MAX];
int getroot(int x){
if (par[x]==x) return x;
else return getroot(par[x]);
}
int union_(int x,int y){
int rx = getroot(x);
int ry = getroot(y);
if (rx==ry) return 0;
if (rank[rx]>rank[ry]){
par[ry] = rx;
rank[rx]++;
}
else{
par[rx] = ry;
rank[ry]++;
}
return 0;
}
int main(){
int n;
cin >> n;
for (int i=0;i<n;i++){
int x;scanf("%d",&x);
m[x] = 1;
}
n = 0;
for (int i=1;i<MAX;i++){
if (m[i]){
a[n++] = i;
par[i] = i;
}
}
int groups = n;
int md = 0;
ll sum = 0;
while(groups!=1){
for (int i=0;i<n;i++){
for (int j=a[i]+md;j<MAX;j+=a[i]){
if (m[j] && getroot(a[i])!=getroot(j)){
union_(j,a[i]);
sum+=md;
groups--;
}
}
}
md++;
}
cout << sum << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgSU5GIDEwMDAwMDAwMDAKI2RlZmluZSBNIDEwMDAwMDAwMDcKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBNQVggMTAwMDAwMDEKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIAppbnQgYVtNQVhdLG1bTUFYXTsKaW50IHBhcltNQVhdLHJhbmtbTUFYXTsKIAppbnQgZ2V0cm9vdChpbnQgeCl7CiAgICBpZiAocGFyW3hdPT14KSByZXR1cm4geDsKICAgIGVsc2UgcmV0dXJuIGdldHJvb3QocGFyW3hdKTsKfQogCmludCB1bmlvbl8oaW50IHgsaW50IHkpewogICAgaW50IHJ4ID0gZ2V0cm9vdCh4KTsKICAgIGludCByeSA9IGdldHJvb3QoeSk7CiAgICBpZiAocng9PXJ5KSByZXR1cm4gMDsKICAgIGlmIChyYW5rW3J4XT5yYW5rW3J5XSl7CiAgICAgICAgcGFyW3J5XSA9IHJ4OwogICAgICAgIHJhbmtbcnhdKys7CiAgICB9CiAgICBlbHNlewogICAgICAgIHBhcltyeF0gPSByeTsKICAgICAgICByYW5rW3J5XSsrOwogICAgfQogICAgcmV0dXJuIDA7Cn0KIAppbnQgbWFpbigpewogICAgaW50IG47CiAgICBjaW4gPj4gbjsKICAgIGZvciAoaW50IGk9MDtpPG47aSsrKXsKICAgICAgICBpbnQgeDtzY2FuZigiJWQiLCZ4KTsKICAgICAgICBtW3hdID0gMTsKICAgIH0KICAgIG4gPSAwOwogICAgZm9yIChpbnQgaT0xO2k8TUFYO2krKyl7CiAgICAgICAgaWYgKG1baV0pewogICAgICAgICAgICBhW24rK10gPSBpOwogICAgICAgICAgICBwYXJbaV0gPSBpOwogICAgICAgIH0KICAgIH0KICAgIGludCBncm91cHMgPSBuOwogICAgaW50IG1kID0gMDsKICAgIGxsIHN1bSA9IDA7CiAgICB3aGlsZShncm91cHMhPTEpewogICAgICAgIGZvciAoaW50IGk9MDtpPG47aSsrKXsKICAgICAgICAgICAgZm9yIChpbnQgaj1hW2ldK21kO2o8TUFYO2orPWFbaV0pewogICAgICAgICAgICAgICAgaWYgKG1bal0gJiYgZ2V0cm9vdChhW2ldKSE9Z2V0cm9vdChqKSl7CiAgICAgICAgICAgICAgICAgICAgdW5pb25fKGosYVtpXSk7CiAgICAgICAgICAgICAgICAgICAgc3VtKz1tZDsKICAgICAgICAgICAgICAgICAgICBncm91cHMtLTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBtZCsrOwogICAgfQogICAgY291dCA8PCBzdW0gPDwgZW5kbDsKICAgIHJldHVybiAwOwp9