結果

問題 No.1059 素敵な集合
ユーザー tanon710tanon710
提出日時 2020-05-23 00:17:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 1,053 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 86,840 KB
実行使用メモリ 93,964 KB
最終ジャッジ日時 2023-09-30 15:35:32
合計ジャッジ時間 4,116 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,424 KB
testcase_01 AC 132 ms
80,228 KB
testcase_02 AC 155 ms
80,664 KB
testcase_03 AC 74 ms
71,268 KB
testcase_04 AC 74 ms
71,084 KB
testcase_05 AC 75 ms
71,348 KB
testcase_06 AC 144 ms
78,652 KB
testcase_07 AC 142 ms
78,608 KB
testcase_08 AC 149 ms
80,092 KB
testcase_09 AC 133 ms
78,084 KB
testcase_10 AC 142 ms
79,000 KB
testcase_11 AC 145 ms
79,060 KB
testcase_12 AC 159 ms
78,748 KB
testcase_13 AC 150 ms
80,612 KB
testcase_14 AC 94 ms
76,644 KB
testcase_15 AC 160 ms
82,016 KB
testcase_16 AC 149 ms
79,016 KB
testcase_17 AC 145 ms
80,424 KB
testcase_18 AC 98 ms
93,964 KB
testcase_19 AC 146 ms
80,532 KB
testcase_20 AC 164 ms
81,540 KB
testcase_21 AC 167 ms
83,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0