結果

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

ソースコード

diff #

#include <iostream>

using namespace std; 

const int N = 2e5 + 5;

int t, n, vis[N], a[N];

long long ans, sum[N], tmp;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		vis[a[i]]++;
		sum[a[i]] += a[i];
		ans += a[i];
	}
	for (int i = 1; i <= 200000; i++) {
		sum[i] += sum[i - 1];
	}
	ans *= n;
	for (int i = 1; i <= 200000; i++) {
		if (!vis[i]) {
			continue;
		}
		tmp = 0;
		for (int l = 1, r = 0; l <= i; l = r + 1) {
			r = i / (i / l);
			tmp += 1ll * (i / l) * (sum[r] - sum[l - 1]);
		}
		ans -= 1ll * tmp * vis[i];
	}
	cout << ans;
	return 0;
}
0