結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー t98slider
提出日時 2022-08-24 09:32:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 88 ms / 4,000 ms
コード長 659 bytes
コンパイル時間 1,652 ms
コンパイル使用メモリ 167,760 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-12-16 08:35:59
合計ジャッジ時間 2,964 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int n, v, r = 200000;
    cin >> n;
    vector<ll> cnt(r + 2), s(r + 2);
    for(int i = 0; i < n; i++){
        cin >> v;
        cnt[v + 1]++;
        s[v + 1] += v;
    }
    for(int i = 0; i <= r; i++){
        cnt[i + 1] += cnt[i];
        s[i + 1] += s[i];
    }
    ll ans = 0;
    for(int i = 1; i <= r; i++){
        if(cnt[i + 1] == cnt[i])continue;
        ans += (cnt[r + 1] - cnt[i + 1]) * i;
        for(int j = i; j <= r; j+=i){
            ans -= s[min(r + 1, j + i)] - s[j] - (cnt[min(r + 1, j + i)] - cnt[j]) * j;
        }
    }
    cout << ans << '\n';
}
0