#include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template constexpr T INF = ::numeric_limits::max()/32*15+208; int main() { int n; cin >> n; vector v(n); int M = 400000; vector cnt(M+1); for (auto &&i : v) scanf("%d", &i), cnt[i]++; vector sum(M+2), cnts(M+2); for (int i = 0; i <= M; ++i) { sum[i+1] = sum[i] + cnt[i]*i; cnts[i+1] = cnts[i] + cnt[i]; } ll ans = 0; for (int i = 2; i <= M; ++i) { for (int j = 0; j <= M; j += i) { int k = min(200001, j+i); ans += (sum[k]-sum[j]-(cnts[k]-cnts[j])*j)*cnt[i]; } } cout << ans << "\n"; return 0; }