結果

問題 No.1059 素敵な集合
ユーザー c-yanc-yan
提出日時 2020-05-23 08:55:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 445 ms / 2,000 ms
コード長 599 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 10,448 KB
最終ジャッジ日時 2023-09-30 15:36:36
合計ジャッジ時間 3,709 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,820 KB
testcase_01 AC 208 ms
9,672 KB
testcase_02 AC 100 ms
9,192 KB
testcase_03 AC 15 ms
7,916 KB
testcase_04 AC 16 ms
7,960 KB
testcase_05 AC 16 ms
7,836 KB
testcase_06 AC 78 ms
8,784 KB
testcase_07 AC 78 ms
8,928 KB
testcase_08 AC 103 ms
9,180 KB
testcase_09 AC 36 ms
8,464 KB
testcase_10 AC 126 ms
8,856 KB
testcase_11 AC 80 ms
8,780 KB
testcase_12 AC 52 ms
8,556 KB
testcase_13 AC 148 ms
9,348 KB
testcase_14 AC 20 ms
8,352 KB
testcase_15 AC 248 ms
9,948 KB
testcase_16 AC 93 ms
9,184 KB
testcase_17 AC 92 ms
9,092 KB
testcase_18 AC 77 ms
9,612 KB
testcase_19 AC 445 ms
9,840 KB
testcase_20 AC 386 ms
9,896 KB
testcase_21 AC 252 ms
10,448 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