結果

問題 No.1233 割り切れない気持ち
ユーザー vjudge1vjudge1
提出日時 2024-05-02 11:39:20
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 863 bytes
コンパイル時間 2,013 ms
コンパイル使用メモリ 200,080 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2024-11-23 01:06:12
合計ジャッジ時間 51,199 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15 WA * 16 TLE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

int t, n;

long long a[N], ans, maxi, p[N], sum[N];

char u;

void Solve() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		maxi = max(maxi, a[i]);
		p[a[i]]++;
		sum[a[i]] += a[i];
	}
	for (int i = 1; i <= maxi; i++) {
		p[i] += p[i - 1];
		sum[i] += sum[i - 1];
	}
	for (int i = 1; i <= n; i++) {
		ans += a[i] * n;
		int tmp = 0;
	//	cout << "Case :" << i << "\n";
		for (int l = 1, r = 0; l <= maxi && r <= maxi; l = r + 1) {
			if (!(a[i] / l)) {
				break;
			}
			r = a[i] / (a[i] / l);
			tmp += (a[i] / l) * (sum[r] - sum[l - 1]); 
		//	cout << l << " " << r << " " << (p[r] - p[l - 1]) << " " << (a[i] / l) * r << "\n";
		}
		ans -= tmp;
	}
	cout << ans;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
//	cin >> t;
//	while (t--) {
		Solve();
//	}
	return 0;
}
0