結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,876 KB
testcase_01 AC 201 ms
9,600 KB
testcase_02 AC 95 ms
9,148 KB
testcase_03 AC 16 ms
7,824 KB
testcase_04 AC 16 ms
7,872 KB
testcase_05 AC 17 ms
7,804 KB
testcase_06 AC 73 ms
8,576 KB
testcase_07 AC 70 ms
8,584 KB
testcase_08 AC 97 ms
9,100 KB
testcase_09 AC 35 ms
8,292 KB
testcase_10 AC 115 ms
8,936 KB
testcase_11 AC 77 ms
8,628 KB
testcase_12 AC 49 ms
8,500 KB
testcase_13 AC 140 ms
9,336 KB
testcase_14 AC 20 ms
8,260 KB
testcase_15 AC 231 ms
9,852 KB
testcase_16 AC 88 ms
8,840 KB
testcase_17 AC 85 ms
8,880 KB
testcase_18 AC 80 ms
9,676 KB
testcase_19 AC 374 ms
9,576 KB
testcase_20 AC 358 ms
9,968 KB
testcase_21 AC 240 ms
10,192 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
    if i > j:
        i, j = j, i
    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