結果
| 問題 |
No.1059 素敵な集合
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-23 00:17:08 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 132 ms / 2,000 ms |
| コード長 | 1,053 bytes |
| コンパイル時間 | 154 ms |
| コンパイル使用メモリ | 82,252 KB |
| 実行使用メモリ | 82,264 KB |
| 最終ジャッジ日時 | 2024-07-23 09:35:42 |
| 合計ジャッジ時間 | 3,094 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
class UnionFind():
def __init__(self,n):
self.n=n
self.root=[-1]*(n+1)
self.rank=[0]*(n+1)
def FindRoot(self,x):
if self.root[x]<0:
return x
else:
self.root[x]=self.FindRoot(self.root[x])
return self.root[x]
def Unite(self,x,y):
x=self.FindRoot(x)
y=self.FindRoot(y)
if x==y:
return
else:
if self.rank[x]>self.rank[y]:
self.root[x]+=self.root[y]
self.root[y]=x
elif self.rank[x]<=self.rank[y]:
self.root[y]+=self.root[x]
self.root[x]=y
if self.rank[x]==self.rank[y]:
self.rank[y]+=1
def isSameGroup(self,x,y):
return self.FindRoot(x)==self.FindRoot(y)
def Count(self,x):
return -self.root[self.FindRoot(x)]
l,r=map(int,input().split())
t=UnionFind(r+1)
for i in range(l,r+1):
for j in range(2,r//l+1):
if i*j>r:
break
t.Unite(i,i*j)
ans=0
s=set()
for i in range(l,r+1):
if t.FindRoot(i) in s:
continue
else:
s.add(t.FindRoot(i))
ans+=1
print(ans-1)