結果
問題 | No.2046 Ans Mod? Mod Ans! |
ユーザー |
|
提出日時 | 2022-08-24 09:33:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 39 ms / 4,000 ms |
コード長 | 730 bytes |
コンパイル時間 | 1,763 ms |
コンパイル使用メモリ | 169,240 KB |
実行使用メモリ | 7,040 KB |
最終ジャッジ日時 | 2024-12-16 08:36:08 |
合計ジャッジ時間 | 2,814 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, v, r = 200000; cin >> n; vector<int> a(n); vector<ll> cnt(r + 2), s(r + 2); for(int i = 0; i < n; i++){ cin >> v; cnt[v + 1]++; s[v + 1] += v; } for(int i = 0; i <= r; i++){ cnt[i + 1] += cnt[i]; s[i + 1] += s[i]; } ll ans = 0; for(int i = 1; i <= r; i++){ if(cnt[i + 1] == cnt[i])continue; ans += (cnt[r + 1] - cnt[i + 1]) * i; for(int j = i; j <= r; j+=i){ ans -= s[min(r + 1, j + i)] - s[j] - (cnt[min(r + 1, j + i)] - cnt[j]) * j; } } cout << ans << '\n'; }