結果

問題 No.826 連絡網
ユーザー tnodinotnodino
提出日時 2022-06-15 18:29:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 933 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 27,776 KB
最終ジャッジ日時 2024-04-15 03:37:43
合計ジャッジ時間 14,017 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,752 KB
testcase_01 AC 27 ms
10,880 KB
testcase_02 AC 28 ms
10,752 KB
testcase_03 AC 33 ms
10,880 KB
testcase_04 AC 34 ms
11,008 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 AC 33 ms
10,880 KB
testcase_07 AC 37 ms
11,008 KB
testcase_08 AC 34 ms
11,008 KB
testcase_09 AC 36 ms
11,008 KB
testcase_10 AC 29 ms
10,880 KB
testcase_11 AC 31 ms
10,880 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 38 ms
11,008 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, sz):
        self.par = [-1] * (sz+1)

    def root(self, pos):
        if self.par[pos] < 0:
            return pos
        self.par[pos] = self.root(self.par[pos])
        return self.par[pos]

    def unite(self, u, v):
        u = self.root(u)
        v = self.root(v)
        if u == v:
            return
        self.par[u] += self.par[v]
        self.par[v] = u

    def same(self, u, v):
        if self.root(u) == self.root(v):
            return True
        return False

    def size(self, pos):
        return -self.par[self.root(pos)]

def sieve_of_eratosthenes(N):
    P = UnionFind(N)
    flg = [0] * (N+1)
    for i in range(2,N+1):
        if flg[i] == 0:
            idx = i
            while idx <= N:
                P.unite(i, idx)
                flg[idx] = 1
                idx += i
    return P

N,P = map(int,input().split())
print(sieve_of_eratosthenes(N).size(P))
0