結果

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

ソースコード

diff #

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

int n;
ll a[200002];
ll cnt[400002];
void solve() {
    cin >> n;

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

    for (int i = 1;i <= 400001;i++) cnt[i] += cnt[i - 1];

    for (int mod = 1;mod <= 200000;mod++) {
        ll mod_cnt = cnt[mod] - cnt[mod - 1];
        for (int k = 0;mod * k <= 200000;k++) {
            ll c = cnt[(k + 1) * mod - 1];
            if (k * mod - 1 >= 0) c -= cnt[k * mod - 1];
            ans -= c * mod_cnt * (mod * k);
        }
    }
    cout << ans;
}

/*
a%b = a - ky
??k

??-ky?
ky<=a<(k+1)y
*/
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    int t = 1;
    // cin >> t;
    while (t--)
        solve();
}
0