#include using namespace std; template void cmax(T &a, U b) { if (a < b) a = b; } template void cmin(T &a, U b) { if (a > b) a = b; } template class FenwickTree { int N, M; vector B; public: FenwickTree(int n) : N(n + 1), M(1), B(N, 0) { while (M * 2 <= N) M *= 2; } FenwickTree(const vector &v) : N((int) v.size() + 1), M(1), B(N, 0) { for (int i = 0; i < N - 1; i++) add(i, v.at(i)); while (M * 2 <= N) M *= 2; } void add(int i, T x) { i++; while (i < N) B.at(i) += x, i += i & -i; } void add(int l, int r, T x) { add(l, x); add(r + 1 , -x); } T sum(int i) { i++; T ret = 0; while (i > 0) ret += B.at(i), i -= i & -i; return ret; } T sum(int l, int r) { return sum(r) - sum(l - 1); } T at(int i) { return sum(i) - sum(i - 1); } int lower_bound(T w) { if (w <= 0) return 0; int x = 0; for (int k = M; k > 0; k /= 2) { if (x + k <= N - 1 && B.at(x + k) < w) { w -= B.at(x + k); x += k; } } return x; } int upper_bound(T w) { if (w < 0) return 0; int x = 0; for (int k = M; k > 0; k /= 2) { if (x + k <= N - 1 && B.at(x + k) <= w) { w -= B.at(x + k); x += k; } } return x; } }; signed main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int N; cin >> N; vector A(N); for (int i = 0; i < N; i++) cin >> A.at(i); int M = 2e5 + 1; FenwickTree FT(M * 2); for (auto a : A) FT.add(a, 1); long tmp = 0; for (int i = 1; i < M; i++) { for (int j = i; j < M; j += i) { tmp += (long) FT.at(i) * FT.sum(j, j + i - 1) * j; } } long acc = accumulate(A.begin(), A.end(), 0L); cout << acc * N - tmp << "\n"; }