結果
| 問題 |
No.1233 割り切れない気持ち
|
| コンテスト | |
| ユーザー |
QCFium
|
| 提出日時 | 2019-07-31 01:19:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 240 ms / 3,153 ms |
| コード長 | 864 bytes |
| コンパイル時間 | 1,497 ms |
| コンパイル使用メモリ | 167,304 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-22 19:09:54 |
| 合計ジャッジ時間 | 6,375 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 39 |
ソースコード
#include <bits/stdc++.h>
int ri() {
int n;
scanf("%d", &n);
return n;
}
int main() {
int n = ri();
int a[n];
int num_sum[200001] = { 0 };
for (int i = 0; i < n; i++) a[i] = ri(), num_sum[a[i]]++;
int64_t sum = std::accumulate(a, a + n, 0LL);
for (int i = 0; i < 200000; i++) num_sum[i + 1] += num_sum[i];
int64_t cache[400];
for (int i = 0; i < 400; i++) cache[i] = -1;
int64_t res = 0;
for (int i = 0; i < n; i++) {
if (a[i] < 400) {
if (cache[a[i]] == -1) {
cache[a[i]] = 0;
for (int j = 0; j < n; j++) cache[a[i]] += a[j] % a[i];
}
res += cache[a[i]];
} else {
res += sum;
for (int j = 0; j <= 200000 / a[i]; j++) {
int num = num_sum[std::min(200000, (j + 1) * a[i] - 1)];
if (j) num -= num_sum[j * a[i] - 1];
res -= (int64_t) a[i] * j * num;
}
}
}
std::cout << res << std::endl;
return 0;
}
QCFium