//84104971101048411497 - Can you guess what does this mean?
using namespace std;
#include <bits/stdc++.h>
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define ftoa(i, l, r, a) for(int i = (l); i <= (r); i += a)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ll long long
#define sizeX 10000005
#define next abcxyz
#define sz(a) (int)(a.size())
template <class T>
T min(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
T max(T a, T b, T c) {
return max(a, max(b, c));
}
template <class T>
void read(vector<T> &v) {
T x;
cin >> x;
v.pb(x);
}
struct edge {
int u, v, c;
edge() {}
edge(int u, int v, int c): u(u), v(v), c(c) {}
bool inline operator < (const edge &o) const {
return c < o.c;
}
};
int n, next[sizeX];
bool avail[sizeX];
vector<int> a;
vector<edge> e;
class UFDS {
private: int n; vector<int> pset;
public:
UFDS(int n) {
pset.resize(n);
fto(i, 0, n-1) pset[i] = i;
}
int findSet(int u) {
return (pset[u] == u) ? u : pset[u] = findSet(pset[u]);
}
bool unionSet(int u, int v) {
int p = findSet(u), q = findSet(v);
if (p == q) return false;
pset[p] = q;
return true;
}
};
int main () {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
scanf("%d", &n);
int maxX = 0;
fto(i, 0, n-1) {
int x; scanf("%d", &x);
avail[x] = true;
maxX = max(maxX, x);
}
next[maxX+1] = -1;
fdto(x, maxX, 1) {
if (avail[x]) {
next[x] = sz(a);
a.pb(x);
} else next[x] = next[x+1];
}
memset(avail, false, sizeof avail);
fto(i, 0, sz(a)-1) {
vector<int> save;
ftoa(k, a[i], maxX, a[i]) {
int j = next[k + (k == a[i])];
if (j >= 0 && !avail[j]) {
e.pb(edge(i, j, a[j]%a[i]));
avail[j] = true; save.pb(j);
}
}
forit(it, save) avail[*it] = false;
}
sort(e.begin(), e.end());
UFDS s(a.size());
int ans = 0;
forit(it, e) {
if (s.unionSet(it->u, it->v)) ans += it->c;
}
printf("%d", ans);
return 0;
}
Ly84NDEwNDk3MTEwMTA0ODQxMTQ5NyAtIENhbiB5b3UgZ3Vlc3Mgd2hhdCBkb2VzIHRoaXMgbWVhbj8KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbWFwaWkgbWFwPGludCwgaW50PgojZGVmaW5lIGRlYnVnKGEpIGNvdXQgPDwgI2EgPDwgIjogIiA8PCBhIDw8IGVuZGwKI2RlZmluZSBkZWJ1Z2ExKGEsIGwsIHIpIGZ0byhpLCBsLCByKSBjb3V0IDw8IGFbaV0gPDwgIiAiOyBjb3V0IDw8IGVuZGwKI2RlZmluZSBmZHRvKGksIHIsIGwpIGZvcihpbnQgaSA9IChyKTsgaSA+PSAobCk7IC0taSkKI2RlZmluZSBmdG8oaSwgbCwgcikgZm9yKGludCBpID0gKGwpOyBpIDw9IChyKTsgKytpKQojZGVmaW5lIGZ0b2EoaSwgbCwgciwgYSkgZm9yKGludCBpID0gKGwpOyBpIDw9IChyKTsgaSArPSBhKQojZGVmaW5lIGZvcml0KGl0LCB2YXIpIGZvcihfX3R5cGVvZih2YXIuYmVnaW4oKSkgaXQgPSB2YXIuYmVnaW4oKTsgaXQgIT0gdmFyLmVuZCgpOyBpdCsrKQojZGVmaW5lIGZvcnJpdChyaXQsIHZhcikgZm9yKF9fdHlwZW9mKHZhci5yYmVnaW4oKSkgcml0ID0gdmFyLnJiZWdpbigpOyByaXQgIT0gdmFyLnJlbmQoKTsgcml0KyspCiNkZWZpbmUgaW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IDAsIG4tMSkgcHNldFtpXSA9IGk7CiAgICB9CiAgICBpbnQgZmluZFNldChpbnQgdSkgewogICAgICAgIHJldHVybiAocHNldFt1XSA9PSB1KSA/IHUgOiBwc2V0W3VdID0gZmluZFNldChwc2V0W3VdKTsKICAgIH0KICAgIGJvb2wgdW5pb25TZXQoaW50IHUsIGludCB2KSB7CiAgICAgICAgaW50IHAgPSBmaW5kU2V0KHUpLCBxID0gZmluZFNldCh2KTsKICAgICAgICBpZiAocCA9PSBxKSByZXR1cm4gZmFsc2U7CiAgICAgICAgcHNldFtwXSA9IHE7CiAgICAgICAgcmV0dXJuIHRydWU7CiAgICB9Cn07CgppbnQgbWFpbiAoKSB7CiAgICAjaWZuZGVmIE9OTElORV9KVURHRQogICAgICAgIGZyZW9wZW4oImlucHV0LnR4dCIsICJyIiwgc3RkaW4pOwogICAgICAgIC8vZnJlb3Blbigib3V0cHV0LnR4dCIsICJ3Iiwgc3Rkb3V0KTsKICAgICNlbmRpZiAvLyBPTkxJTkVfSlVER0UKCiAgICBzY2FuZigiJWQiLCAmbik7CiAgICBpbnQgbWF4WCA9IDA7CiAgICBmdG8oaSwgMCwgbi0xKSB7CiAgICAgICAgaW50IHg7IHNjYW5mKCIlZCIsICZ4KTsKICAgICAgICBhdmFpbFt4XSA9IHRydWU7CiAgICAgICAgbWF4WCA9IG1heChtYXhYLCB4KTsKICAgIH0KCiAgICBuZXh0W21heFgrMV0gPSAtMTsKICAgIGZkdG8oeCwgbWF4WCwgMSkgewogICAgICAgIGlmIChhdmFpbFt4XSkgewogICAgICAgICAgICBuZXh0W3hdID0gc3ooYSk7CiAgICAgICAgICAgIGEucGIoeCk7CiAgICAgICAgfSBlbHNlIG5leHRbeF0gPSBuZXh0W3grMV07CiAgICB9CgogICAgbWVtc2V0KGF2YWlsLCBmYWxzZSwgc2l6ZW9mIGF2YWlsKTsKICAgIGZ0byhpLCAwLCBzeihhKS0xKSB7CiAgICAgICAgdmVjdG9yPGludD4gc2F2ZTsKICAgICAgICBmdG9hKGssIGFbaV0sIG1heFgsIGFbaV0pIHsKICAgICAgICAgICAgaW50IGogPSBuZXh0W2sgKyAoayA9PSBhW2ldKV07CiAgICAgICAgICAgIGlmIChqID49IDAgJiYgIWF2YWlsW2pdKSB7CiAgICAgICAgICAgICAgICBlLnBiKGVkZ2UoaSwgaiwgYVtqXSVhW2ldKSk7CiAgICAgICAgICAgICAgICBhdmFpbFtqXSA9IHRydWU7IHNhdmUucGIoaik7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yaXQoaXQsIHNhdmUpIGF2YWlsWyppdF0gPSBmYWxzZTsKICAgIH0KCiAgICBzb3J0KGUuYmVnaW4oKSwgZS5lbmQoKSk7CgogICAgVUZEUyBzKGEuc2l6ZSgpKTsKICAgIGludCBhbnMgPSAwOwogICAgZm9yaXQoaXQsIGUpIHsKICAgICAgICBpZiAocy51bmlvblNldChpdC0+dSwgaXQtPnYpKSBhbnMgKz0gaXQtPmM7CiAgICB9CgogICAgcHJpbnRmKCIlZCIsIGFucyk7CgogICAgcmV0dXJuIDA7Cn0KCg==