結果

問題 No.1059 素敵な集合
ユーザー RITIK KUMAR GUPTARITIK KUMAR GUPTA
提出日時 2020-05-24 13:53:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 428 ms / 2,000 ms
コード長 598 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 10,812 KB
実行使用メモリ 10,424 KB
最終ジャッジ日時 2023-09-30 15:37:56
合計ジャッジ時間 3,770 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,792 KB
testcase_01 AC 199 ms
9,528 KB
testcase_02 AC 103 ms
9,204 KB
testcase_03 AC 16 ms
7,884 KB
testcase_04 AC 15 ms
7,876 KB
testcase_05 AC 16 ms
7,852 KB
testcase_06 AC 77 ms
8,752 KB
testcase_07 AC 74 ms
8,836 KB
testcase_08 AC 105 ms
9,204 KB
testcase_09 AC 35 ms
8,372 KB
testcase_10 AC 122 ms
8,916 KB
testcase_11 AC 81 ms
8,796 KB
testcase_12 AC 51 ms
8,632 KB
testcase_13 AC 148 ms
9,192 KB
testcase_14 AC 20 ms
8,356 KB
testcase_15 AC 248 ms
10,212 KB
testcase_16 AC 91 ms
8,948 KB
testcase_17 AC 90 ms
9,072 KB
testcase_18 AC 79 ms
9,572 KB
testcase_19 AC 428 ms
9,876 KB
testcase_20 AC 395 ms
9,908 KB
testcase_21 AC 253 ms
10,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit


def find(parent, i):
    t = parent[i]
    if t < 0:
        return i
    t = find(parent, t)
    parent[i] = t
    return t


def unite(parent, i, j):
    i = find(parent, i)
    j = find(parent, j)
    if i == j:
        return
    parent[i] += parent[j]
    parent[j] = i


setrecursionlimit(10 ** 6)

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

parent = [-1] * (R + 1)
for i in range(L, R):
    if find(parent, i) != i:
        continue
    for j in range(i * 2, R + 1, i):
        unite(parent, i, j)
print(sum(1 for i in range(L, R + 1) if find(parent, i) == i) - 1)
0