結果

問題 No.826 連絡網
ユーザー tnodinotnodino
提出日時 2022-06-15 18:30:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 407 ms / 2,000 ms
コード長 993 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 196,064 KB
最終ジャッジ日時 2024-04-15 03:38:45
合計ジャッジ時間 5,745 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,224 KB
testcase_01 AC 39 ms
52,096 KB
testcase_02 AC 44 ms
60,288 KB
testcase_03 AC 66 ms
71,680 KB
testcase_04 AC 67 ms
72,960 KB
testcase_05 AC 59 ms
68,608 KB
testcase_06 AC 60 ms
68,096 KB
testcase_07 AC 69 ms
72,448 KB
testcase_08 AC 60 ms
68,864 KB
testcase_09 AC 65 ms
72,320 KB
testcase_10 AC 55 ms
67,456 KB
testcase_11 AC 65 ms
72,064 KB
testcase_12 AC 278 ms
150,172 KB
testcase_13 AC 149 ms
107,748 KB
testcase_14 AC 234 ms
135,688 KB
testcase_15 AC 89 ms
82,048 KB
testcase_16 AC 165 ms
110,488 KB
testcase_17 AC 147 ms
106,456 KB
testcase_18 AC 126 ms
100,760 KB
testcase_19 AC 322 ms
172,272 KB
testcase_20 AC 145 ms
90,368 KB
testcase_21 AC 66 ms
73,344 KB
testcase_22 AC 151 ms
107,776 KB
testcase_23 AC 188 ms
123,232 KB
testcase_24 AC 103 ms
86,400 KB
testcase_25 AC 389 ms
195,792 KB
testcase_26 AC 125 ms
100,804 KB
testcase_27 AC 266 ms
151,196 KB
testcase_28 AC 253 ms
147,040 KB
testcase_29 AC 148 ms
107,544 KB
testcase_30 AC 407 ms
196,064 KB
testcase_31 AC 164 ms
109,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit
setrecursionlimit(10**6)

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