#include int ri() { int n; scanf("%d", &n); return n; } int main() { int n = ri(); std::map a; std::map > sum; for (int i = 0; i < n; i++) a[ri()]++; std::pair cur = {0, 0}; for (auto &i : a) { sum[i.first] = cur; cur.first += i.second; cur.second += (int64_t) i.first * i.second; } int cache[401]; for (int i = 0; i <= 400; i++) cache[i] = -1; int64_t ans = 0; for (auto &i : a) { int64_t res = 0; if (i.first <= 400) { if (cache[i.first] == -1) { cache[i.first] = 0; for (auto &j : a) cache[i.first] += (j.first % i.first) * j.second; } res = cache[i.first]; } else { for (int j = 0; j < 200000; j += i.first) { auto low = sum.lower_bound(j); auto high = sum.lower_bound(j + i.first); int64_t xsum = (high == sum.end() ? cur.second : high->second.second) - (low == sum.end() ? cur.second : low->second.second); int num = (high == sum.end() ? cur.first : high->second.first) - (low == sum.end() ? cur.first : low->second.first); // std::cerr << xsum << " " << num * i.first * (j / i.first) << std::endl; res += xsum; res -= (int64_t) num * i.first * (j / i.first); } } res *= i.second; ans += res; } std::cout << ans << std::endl; return 0; }