#include <cstdio>
#include <iostream>
const int N = int(1e6) + 2;
int n, x;
int a[N];
long long s[N], c[N];
long long ans;
int main()
{
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d", &x);
a[x]++;
}
for (long long i = 1; i <= n; i++)
{
c[i] = c[i - 1] + a[i];
s[i] = s[i - 1] + a[i] * i;
}
for (int i = 1; i <= n; i++)
{
ans += s[i - 1] * a[i];
for (int j = i; j <= n; j += i)
{
int k = std::min(n, j + i - 1);
ans += (s[k] - s[j - 1] - (c[k] - c[j - 1]) * j) * a[i];
}
}
std::cout << ans;
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKY29uc3QgaW50IE4gPSBpbnQoMWU2KSArIDI7CgppbnQgbiwgeDsKaW50IGFbTl07CmxvbmcgbG9uZyBzW05dLCBjW05dOwpsb25nIGxvbmcgYW5zOwoKaW50IG1haW4oKQp7CglmcmVvcGVuKCJpbnB1dC50eHQiLCAicnQiLCBzdGRpbik7CglmcmVvcGVuKCJvdXRwdXQudHh0IiwgInd0Iiwgc3Rkb3V0KTsKCglzY2FuZigiJWQiLCAmbik7CgoJZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspCgl7CgkJc2NhbmYoIiVkIiwgJngpOwoKCQlhW3hdKys7Cgl9CgoJZm9yIChsb25nIGxvbmcgaSA9IDE7IGkgPD0gbjsgaSsrKQoJewoJCWNbaV0gPSBjW2kgLSAxXSArIGFbaV07CgkJc1tpXSA9IHNbaSAtIDFdICsgYVtpXSAqIGk7Cgl9CgoJZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKQoJewoJCWFucyArPSBzW2kgLSAxXSAqIGFbaV07CgoJCWZvciAoaW50IGogPSBpOyBqIDw9IG47IGogKz0gaSkKCQl7CgkJCWludCBrID0gc3RkOjptaW4obiwgaiArIGkgLSAxKTsKCgkJCWFucyArPSAoc1trXSAtIHNbaiAtIDFdIC0gKGNba10gLSBjW2ogLSAxXSkgKiBqKSAqIGFbaV07CgkJfQoJfQoKCXN0ZDo6Y291dCA8PCBhbnM7CgoJcmV0dXJuIDA7Cn0=