結果

問題 No.1233 割り切れない気持ち
コンテスト
ユーザー milanis48663220
提出日時 2020-09-18 22:07:28
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 327 ms / 3,153 ms
コード長 906 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 673 ms
コンパイル使用メモリ 102,608 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2026-03-07 00:25:16
合計ジャッジ時間 6,969 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N;
ll a[200000];
ll sum[200005];


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    ll sum_all = 0;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        sum_all += a[i];
    }
    sort(a, a+N);
    ll ans = sum_all*N;
    for(int i = 1; i <= 200000; i++){
        for(int j = 0; i*j <= 200000; j++){
            // i*j <= x < i*(j+1)をもとめたい
            auto pl = lower_bound(a, a+N, i*j);
            auto pr = lower_bound(a, a+N, i*(j+1));
            ll cnt = pr-pl;
            sum[i] += cnt*j*i;
        }
    }
    for(int i = 0; i < N; i++){
        ans -= sum[a[i]];
        // cout << sum[a[i]] << endl;
    }
    cout << ans << endl;
}
0