結果

問題 No.1233 割り切れない気持ち
コンテスト
ユーザー vjudge1
提出日時 2025-08-15 15:45:57
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 19 ms / 3,153 ms
+ 812µs
コード長 767 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,172 ms
コンパイル使用メモリ 209,180 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2026-07-14 01:26:48
合計ジャッジ時間 3,816 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

const int N = 4e5 + 10;

int n, a[N], cnt[N], ans, sum;

signed main(){
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//  freopen("mod.in", "r", stdin);
//  freopen("mod.out", "w", stdout);
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
    cnt[a[i]]++;
    ans += n * a[i];
  }
  for(int i = 1; i <= 4e5; i++){
    cnt[i] += cnt[i - 1];
  }
  for(int i = 1; i <= 2e5; i++){
    int ttt = cnt[i] - cnt[i - 1];
    for(int j = 0; j * i <= 2e5; j++){
      int c = 0;
      if(j * i - 1 >= 0){
        c = cnt[(j + 1) * i - 1] - cnt[i * j - 1];
      }
      else{
        c = cnt[(j + 1) * i - 1];
      }
      sum += c * ttt * i * j;
    }
  }
  cout << ans - sum;
  return 0;
}
0