#include #ifdef DEBUG #include #else #define dump(...) ((void)0) #endif template bool chmin(T &a, const U &b){ return (a > b ? a = b, true : false); } template bool chmax(T &a, const U &b){ return (a < b ? a = b, true : false); } template void fill_array(T (&a)[N], const U &v){ std::fill((U*)a, (U*)(a + N), v); } template auto make_vector(const std::array &a, T value = T()){ static_assert(I >= 1); static_assert(N >= 1); if constexpr (I == 1){ return std::vector(a[N - I], value); }else{ return std::vector(a[N - I], make_vector(a, value)); } } template std::ostream& operator<<(std::ostream &s, const std::vector &a){ for(auto it = a.begin(); it != a.end(); ++it){ if(it != a.begin()) s << " "; s << *it; } return s; } template std::istream& operator>>(std::istream &s, std::vector &a){ for(auto &x : a) s >> x; return s; } namespace haar_lib { template , typename Minus = std::minus> class cumulative_sum_1d { std::vector data; const int N; const Add add; const Minus minus; bool is_built = false; public: cumulative_sum_1d(const std::vector &a, const T &e = 0, const Add &add = Add(), const Minus &minus = Minus()): N(a.size()), add(add), minus(minus) { data.assign(N + 1, e); for(int i = 0; i < N; ++i) data[i + 1] = a[i]; } cumulative_sum_1d(int N, const T &e = 0, const Add &add = Add(), const Minus &minus = Minus()): N(N), add(add), minus(minus) { data.assign(N + 1, e); } auto& update(int i, const T &val){ assert(not is_built); data[i + 1] = add(data[i + 1], val); return *this; } auto& build(){ assert(not is_built); for(int i = 0; i < N; ++i) data[i + 1] = add(data[i + 1], data[i]); is_built = true; return *this; } /** * @attention [i, j) */ T get(int i, int j) const { assert(is_built); return minus(data[j], data[i]); } }; } namespace haar_lib {} namespace solver { using namespace haar_lib; constexpr int m1000000007 = 1000000007; constexpr int m998244353 = 998244353; void init(){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(12); std::cerr << std::fixed << std::setprecision(12); std::cin.exceptions(std::ios_base::failbit); } constexpr int MAX = 20; void solve(){ int N; std::cin >> N; std::vector A(N); std::cin >> A; std::vector count(MAX + 1); for(auto x : A) count[x] += 1; cumulative_sum_1d cs(count); cs.build(); int64_t sum = std::accumulate(A.begin(), A.end(), 0LL); int64_t ans = 0; dump(cs.get(1, MAX + 1)); for(int i = 1; i <= MAX; ++i){ if(count[i] == 0) continue; ans += sum * count[i]; dump(ans); for(int j = i; j <= MAX; j += i){ ans -= (int64_t)i * cs.get(j, MAX + 1) * count[i]; } dump(ans); } std::cout << ans << "\n"; } } int main(){ solver::init(); while(true){ try{ solver::solve(); }catch(const std::istream::failure &e){ break; } } return 0; }