結果

問題 No.1233 割り切れない気持ち
ユーザー vjudge1
提出日時 2024-05-02 12:55:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 765 bytes
コンパイル時間 2,093 ms
コンパイル使用メモリ 194,432 KB
最終ジャッジ日時 2025-02-21 10:34:01
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 4 WA * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MAXN = 200001;

int n, a[MAXN], tot, Max, l, r, x;
long long ans, sum[MAXN];

int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for(int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  for(int i = 1; i <= n; ++i) {
    if(!tot || a[i] > a[tot]) {
      a[++tot] = a[i];
    }
  }
  n = tot;
  for(int i = 1; i <= n; ++i) {
    sum[a[i]] += a[i], ans += 1ll * a[i] * n, Max = max(Max, a[i]);
  }
  for(int i = 1; i <= Max; ++i) {
    sum[i] += sum[i - 1];
  }
  for(int i = 1; i <= n; ++i) {
    for(l = 1; l <= a[i]; l = r + 1) {
      x = a[i] / l;
      r = a[i] / x;
      ans -= 1ll * x * (sum[r] - sum[l - 1]);
    }
  }
  cout << ans;
  return 0;
}
0