結果

問題 No.1233 割り切れない気持ち
ユーザー vjudge1
提出日時 2025-08-15 15:48:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 34 ms / 3,153 ms
コード長 807 bytes
コンパイル時間 2,110 ms
コンパイル使用メモリ 193,852 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-15 15:48:58
合計ジャッジ時間 4,948 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int N = 2e5 + 1;
int n;
ll a[N];

ll cnt[N];
ll ans;

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

///    freopen("mod.in", "r", stdin);
///    freopen("mod.out", "w", stdout);

    cin >> n;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
        cnt[a[i]] ++;
        ans += a[i] * n;
    }

    for(int i = 1; i < N; i ++){
        cnt[i] += cnt[i - 1];
    }

    for(int mod = 1; mod < N; mod ++){
        for(int k = 0; k * mod < N; k ++){
            ans -= (cnt[min((k + 1) * mod - 1, N - 1)] - (k * mod - 1 >= 0 ? cnt[k * mod - 1] : 0)) * (cnt[mod] - cnt[mod - 1]) * (mod * k);
        }
    }

    cout << ans;

    return 0;
}

/***

3
1 5 3

8
8 8 8 8 8 8 8 8

***/

0