#include using namespace std; using ll = long long; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector a(n, 0); int m = 0; for (int i = 0; i < n; i++) { cin >> a[i]; m = max(m, a[i]); } vector c(m + 1, 0); for (int i = 0; i < n; i++) { c[a[i]]++; } ll ans = 0; for (int i = 1; i <= m; i++) { for (int j = i; j <= m; j++) { ans += c[i] * c[j] * abs(i % j - j % i); } } cout << ans << endl; }