結果

問題 No.1233 割り切れない気持ち
ユーザー kusaf_
提出日時 2024-09-01 10:33:58
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 57 ms / 3,153 ms
コード長 597 bytes
コンパイル時間 3,294 ms
コンパイル使用メモリ 248,120 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-09-01 10:34:05
合計ジャッジ時間 6,923 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll N, M = 2e5;
  cin >> N;

  vector<ll> a(N), c(M + 1, 0);
  ll ans = 0;
  for(auto &i : a) {
    cin >> i;
    ans += i * N;
    c[i]++;
  }

  vector<ll> s(M + 2, 0);

  for(ll i = 0; i < M + 1; i++) { s[i + 1] = s[i] + c[i]; }

  vector<ll> b(M + 1, 0);
  for(ll i = 1; i <= M; i++) {
    for(ll j = 0; j <= M; j += i) { b[i] += (s[min(M + 1, j + i)] - s[j]) * (j / i); }
  }

  for(ll i = 0; i < N; i++) { ans -= a[i] * b[a[i]]; }

  cout << ans << "\n";
}
0