結果

問題 No.1233 割り切れない気持ち
ユーザー YamaKasaYamaKasa
提出日時 2020-09-19 17:42:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 172 ms / 3,153 ms
コード長 1,509 bytes
コンパイル時間 2,326 ms
コンパイル使用メモリ 169,844 KB
実行使用メモリ 18,416 KB
最終ジャッジ日時 2023-09-05 22:48:27
合計ジャッジ時間 7,298 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,492 KB
testcase_01 AC 3 ms
7,476 KB
testcase_02 AC 5 ms
7,428 KB
testcase_03 AC 7 ms
7,456 KB
testcase_04 AC 7 ms
7,652 KB
testcase_05 AC 5 ms
7,456 KB
testcase_06 AC 6 ms
7,480 KB
testcase_07 AC 35 ms
9,548 KB
testcase_08 AC 61 ms
10,764 KB
testcase_09 AC 128 ms
13,576 KB
testcase_10 AC 135 ms
13,976 KB
testcase_11 AC 32 ms
9,364 KB
testcase_12 AC 171 ms
14,912 KB
testcase_13 AC 172 ms
15,012 KB
testcase_14 AC 167 ms
14,916 KB
testcase_15 AC 165 ms
14,932 KB
testcase_16 AC 171 ms
14,924 KB
testcase_17 AC 32 ms
8,992 KB
testcase_18 AC 126 ms
18,416 KB
testcase_19 AC 61 ms
9,004 KB
testcase_20 AC 32 ms
8,996 KB
testcase_21 AC 49 ms
9,196 KB
testcase_22 AC 49 ms
9,320 KB
testcase_23 AC 49 ms
9,044 KB
testcase_24 AC 50 ms
9,072 KB
testcase_25 AC 50 ms
9,052 KB
testcase_26 AC 50 ms
9,056 KB
testcase_27 AC 58 ms
9,004 KB
testcase_28 AC 60 ms
9,064 KB
testcase_29 AC 58 ms
9,060 KB
testcase_30 AC 59 ms
9,196 KB
testcase_31 AC 59 ms
8,996 KB
testcase_32 AC 59 ms
9,056 KB
testcase_33 AC 61 ms
9,000 KB
testcase_34 AC 59 ms
9,016 KB
testcase_35 AC 59 ms
9,004 KB
testcase_36 AC 59 ms
8,996 KB
testcase_37 AC 3 ms
7,428 KB
testcase_38 AC 33 ms
9,048 KB
testcase_39 AC 77 ms
13,792 KB
testcase_40 AC 79 ms
13,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll MAX = 300000;
ll b[MAX + 1]{};
ll c[MAX + 1]{};

int main() {
    int N;
    cin >> N;
    ll A[N];
    ll sum = 0;
    set<int> s;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        b[A[i]]++;
        s.insert(A[i]);
        sum += A[i];
    }
    
    for (int i = 1; i <= MAX; i++) {
        c[i] = c[i - 1] + b[i]; 
    }
    ll ans = sum * N;
    //cout << ans << "\n";
    for (ll i : s) {
        int t = i;
        if (i == 1) {
            ans -= b[1] * sum;
            continue;
        }
        //cout << "***********\n";
        //cout << i << "\n";
        for (ll k = 1; k < MAX; k++) {
            ll l = i * k - 1;
            ll r = min(MAX, i * (k + 1) - 1);
            if (l > 200005) break;
            //cout << l << " " << r << "\n";
            //cout << c[r + 1] - c[l + 1] << " " << b[i * k] << "\n";
            ll e = (c[r] - c[l]) * k * i * b[i];
            ans -= e;
            // if (e < 0) {
            //     cout << l << " " << r << "\n";
            //     cout << c[r] << " " << c[l] << "\n";
            //     cout << k << " aa\n";
            //     break;
            // }
            //cout << e << "\n";
        }
        //cout << ans << "\n";
    }
    cout << ans << "\n";
    // for (int i = 0; i < 100; i++) {
    //     cout << c[i] << "\n";
    // }
    // cout << "\n";
    // for (int i = 0; i < 10; i++) {
    //     cout << c[i] << " ";
    // }
    return 0;
}
0