#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; using Graph = vector>; using ll = long long; typedef pair P_ll; typedef pair P; const ll INF_ll = 1e17; const int INF = 1e8; template bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template using min_priority_queue = priority_queue, greater>; int main() { int N; cin >> N; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } sort(A.begin(), A.end()); vector sumA(N + 1, 0); for (int i = 0; i < N; i++) { sumA[i + 1] = sumA[i] + A[i]; } ll ans = 0; map mp; for (int i = 0; i < N; i++) { if (mp.count(A[i]) > 0) { ans += mp[A[i]]; continue; } ll prev = 0; ll tmp = 0; for (ll j = 1; (j - 1) * A[i] <= A.back(); j++) { ll id = lower_bound(A.begin(), A.end(), j * A[i]) - A.begin(); tmp += (sumA[id] - sumA[prev]) - (j - 1) * A[i] * (id - prev); prev = id; } mp[A[i]] = tmp; ans += tmp; // cout << i << "," << ans << endl; } cout << ans << endl; return 0; }