結果

問題 No.1059 素敵な集合
ユーザー ああいいああいい
提出日時 2022-01-27 19:33:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 820 ms / 2,000 ms
コード長 525 bytes
コンパイル時間 1,799 ms
コンパイル使用メモリ 86,516 KB
実行使用メモリ 255,272 KB
最終ジャッジ日時 2023-08-26 21:22:02
合計ジャッジ時間 7,606 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
71,296 KB
testcase_01 AC 820 ms
255,272 KB
testcase_02 AC 160 ms
80,688 KB
testcase_03 AC 65 ms
71,380 KB
testcase_04 AC 63 ms
71,164 KB
testcase_05 AC 66 ms
71,468 KB
testcase_06 AC 124 ms
79,372 KB
testcase_07 AC 125 ms
79,340 KB
testcase_08 AC 135 ms
79,916 KB
testcase_09 AC 146 ms
78,568 KB
testcase_10 AC 160 ms
86,616 KB
testcase_11 AC 126 ms
80,340 KB
testcase_12 AC 153 ms
78,728 KB
testcase_13 AC 157 ms
81,360 KB
testcase_14 AC 79 ms
76,456 KB
testcase_15 AC 210 ms
84,716 KB
testcase_16 AC 137 ms
79,732 KB
testcase_17 AC 132 ms
80,012 KB
testcase_18 AC 87 ms
92,092 KB
testcase_19 AC 757 ms
161,628 KB
testcase_20 AC 717 ms
137,512 KB
testcase_21 AC 180 ms
84,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

L,R = map(int,input().split())

parent = list(range(R+1))
import sys
sys.setrecursionlimit(10 ** 8)
def find(i):
    if parent[i] == i:return i
    parent[i] = find(parent[i])
    return parent[i]
def unite(i,j):
    I = find(i)
    J = find(j)
    if I == J:return False
    parent[I] = J
    parent[i] = J
    return True
def isSame(i,j):
    return find(i) == find(j)

for i in range(L,R+1):
    for j in range(i * 2,R+1,i):
        unite(i,j)
ans = 0
s = set()
for i in range(L,R+1):
    s.add(find(i))
print(len(s) - 1)
0