結果
問題 |
No.1059 素敵な集合
|
ユーザー |
|
提出日時 | 2024-10-05 12:20:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 145 ms / 2,000 ms |
コード長 | 855 bytes |
コンパイル時間 | 252 ms |
コンパイル使用メモリ | 82,460 KB |
実行使用メモリ | 83,220 KB |
最終ジャッジ日時 | 2024-10-05 12:20:41 |
合計ジャッジ時間 | 3,064 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
L, R = map(int, input().split()) class UnionFind: def __init__(self, n=1): self.parent = [i for i in range(n)] self.rank = [0] * n def find(self, x): if self.parent[x] == x: return x else: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.parent[y] = x def is_same(self, x, y): return self.find(x) == self.find(y) uf = UnionFind(R-L+1) for i in range(L, R): for j in range(i, R+1, i): uf.union(i-L, j-L) print(len(set([uf.find(i) for i in range(R-L+1)]))-1)