結果

問題 No.1059 素敵な集合
ユーザー ooaiu
提出日時 2025-02-05 04:18:16
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 500 bytes
コンパイル時間 4,263 ms
コンパイル使用メモリ 282,420 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-02-05 04:18:24
合計ジャッジ時間 6,118 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using ll = long long;
int main() {
	int L, R;
	cin >> L >> R;
	if(L == 1) {
		cout << 0 << endl;
		return 0;
	}
	vector<array<int, 3>> E;
	atcoder::dsu uf(R - L + 1);
	for(int i = L; i <= R; i++) {
		for(int j = 2 * i; j <= R; j += i) {
			uf.merge(i - L, j - L);
		}
	}
	int ans = 0;
	for(int i = L; i + 1 <= R; i++) {
		if(!uf.same(i - L, i + 1 - L)) {
			uf.merge(i - L, i + 1 - L);
			ans ++;
		}
	}
	cout << ans << endl;
}

	
0