結果

問題 No.826 連絡網
ユーザー stngstng
提出日時 2022-07-09 17:03:23
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,163 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 118,348 KB
最終ジャッジ日時 2023-08-30 00:44:19
合計ジャッジ時間 5,560 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
75,840 KB
testcase_01 AC 70 ms
71,352 KB
testcase_02 AC 76 ms
75,544 KB
testcase_03 AC 107 ms
77,680 KB
testcase_04 AC 108 ms
77,636 KB
testcase_05 AC 103 ms
77,724 KB
testcase_06 AC 104 ms
77,680 KB
testcase_07 AC 107 ms
78,020 KB
testcase_08 AC 103 ms
77,800 KB
testcase_09 AC 111 ms
77,644 KB
testcase_10 AC 88 ms
76,564 KB
testcase_11 AC 106 ms
77,628 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1 for _ in range(n+1)]
    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

n,p = map(int,input().split())
ki = UnionFind(n+1)
chk = [0]*(n+1)

for i in range(2,n):
    if chk[i] == 1:
        continue
    tmp = 2
    while tmp*i <= n:
        ki.union(i,tmp*i)
        chk[tmp*i] = 1
        tmp += 1
        #print(i,tmp*i)

ans = 0
idx = ki.par[p]

for i in range(n):
    if ki.par[i+1] == idx:
        ans += 1

print(ans)
0