結果

問題 No.826 連絡網
ユーザー TakoKurageTakoKurage
提出日時 2019-05-03 22:23:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,139 bytes
コンパイル時間 121 ms
コンパイル使用メモリ 11,016 KB
実行使用メモリ 27,220 KB
最終ジャッジ日時 2023-08-30 06:12:15
合計ジャッジ時間 21,562 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,228 KB
testcase_01 AC 16 ms
8,396 KB
testcase_02 AC 17 ms
8,356 KB
testcase_03 AC 28 ms
8,420 KB
testcase_04 AC 32 ms
8,504 KB
testcase_05 AC 22 ms
8,364 KB
testcase_06 AC 22 ms
8,380 KB
testcase_07 AC 30 ms
8,420 KB
testcase_08 AC 22 ms
8,376 KB
testcase_09 AC 32 ms
8,568 KB
testcase_10 AC 19 ms
8,356 KB
testcase_11 AC 26 ms
8,332 KB
testcase_12 AC 1,562 ms
21,740 KB
testcase_13 AC 601 ms
13,928 KB
testcase_14 AC 1,139 ms
18,544 KB
testcase_15 AC 136 ms
9,448 KB
testcase_16 AC 746 ms
15,328 KB
testcase_17 AC 599 ms
13,928 KB
testcase_18 AC 468 ms
12,596 KB
testcase_19 AC 1,890 ms
24,080 KB
testcase_20 AC 1,776 ms
23,756 KB
testcase_21 AC 37 ms
8,528 KB
testcase_22 AC 616 ms
13,904 KB
testcase_23 AC 805 ms
15,612 KB
testcase_24 AC 334 ms
11,288 KB
testcase_25 TLE -
testcase_26 AC 399 ms
12,168 KB
testcase_27 AC 1,677 ms
22,352 KB
testcase_28 AC 1,276 ms
19,060 KB
testcase_29 AC 607 ms
13,880 KB
testcase_30 TLE -
testcase_31 AC 714 ms
14,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, size):
        self.data = [-1 for _ in range(size)]

    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return (x != y)

    def same(self, x, y):
        return (self.find(x) == self.find(y))

    def size(self, x):
        return -self.data[self.find(x)]


def prime_table(n):
    list = [True for _ in range(n + 1)]
    i = 2
    while i * i <= n:
        if list[i]:
            j = i + i
            while j <= n:
                list[j] = False
                j += i
        i += 1

    table = [i for i in range(n + 1) if list[i] and i >= 2]
    return table


N, P = [int(i) for i in input().split()]
uf = UnionFind(N + 1)
for p in prime_table(N):
    q = p
    while q <= N:
        uf.union(p, q)
        q += p
print(uf.size(P))
0