結果

問題 No.826 連絡網
ユーザー tnodinotnodino
提出日時 2022-06-15 18:29:33
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 933 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 82,440 KB
実行使用メモリ 92,924 KB
最終ジャッジ日時 2024-04-15 03:37:26
合計ジャッジ時間 4,962 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,068 KB
testcase_01 AC 37 ms
52,264 KB
testcase_02 AC 41 ms
59,644 KB
testcase_03 AC 64 ms
72,512 KB
testcase_04 AC 65 ms
72,732 KB
testcase_05 AC 58 ms
68,352 KB
testcase_06 AC 59 ms
67,840 KB
testcase_07 AC 64 ms
72,372 KB
testcase_08 AC 57 ms
69,016 KB
testcase_09 AC 67 ms
72,652 KB
testcase_10 AC 54 ms
66,816 KB
testcase_11 AC 64 ms
71,808 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 67 ms
73,216 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