結果

問題 No.1233 割り切れない気持ち
ユーザー merom686merom686
提出日時 2020-09-18 22:30:40
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 31 ms / 3,153 ms
コード長 829 bytes
コンパイル時間 1,234 ms
コンパイル使用メモリ 94,228 KB
最終ジャッジ日時 2025-01-14 17:33:19
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    int m = (int)2e+5 + 1;
    vector<int> b(m, 0);
    vector<ll> s(m, 0);
    ll r = 0;

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        b[a]++;
        r += a;
    }
    r *= n;

    for (int a = 1; a < m; a++) {
        ll t = b[a];
        if (t == 0) continue;

        t *= a;
        for (int j = a; j < m; j += a) {
            s[j] += t;
        }
    }
    for (int j = 1; j < m; j++) {
        s[j] += s[j - 1];
    }

    for (int j = 1; j < m; j++) {
        r -= s[j] * b[j];
    }

    cout << r << endl;

    return 0;
}
0