結果

問題 No.1059 素敵な集合
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-03-23 22:42:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 851 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 82,512 KB
実行使用メモリ 77,732 KB
最終ジャッジ日時 2024-04-20 06:44:46
合計ジャッジ時間 2,736 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,492 KB
testcase_01 AC 86 ms
75,812 KB
testcase_02 AC 84 ms
76,444 KB
testcase_03 AC 33 ms
53,260 KB
testcase_04 AC 33 ms
52,620 KB
testcase_05 AC 34 ms
52,664 KB
testcase_06 AC 78 ms
76,384 KB
testcase_07 AC 80 ms
76,368 KB
testcase_08 AC 78 ms
76,532 KB
testcase_09 AC 80 ms
76,328 KB
testcase_10 AC 83 ms
76,688 KB
testcase_11 AC 83 ms
76,456 KB
testcase_12 AC 81 ms
76,432 KB
testcase_13 AC 91 ms
76,852 KB
testcase_14 AC 60 ms
65,312 KB
testcase_15 AC 115 ms
77,176 KB
testcase_16 AC 85 ms
76,348 KB
testcase_17 AC 95 ms
76,696 KB
testcase_18 AC 56 ms
64,356 KB
testcase_19 AC 92 ms
77,444 KB
testcase_20 AC 101 ms
77,732 KB
testcase_21 AC 89 ms
77,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]


l,r = map(int,input().split())
uf = Unionfind(r+1)

for i in range(l,r+1):
    for j in range(i,r+1,i):
        uf.union(i,j)

ans = 0
for i in range(l,r+1):
    if uf.find(i) == i:
        ans += 1
print(ans-1)
0