結果

問題 No.826 連絡網
ユーザー stngstng
提出日時 2022-07-09 17:01:02
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,087 bytes
コンパイル時間 541 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 112,176 KB
最終ジャッジ日時 2023-08-30 00:41:27
合計ジャッジ時間 5,978 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
76,024 KB
testcase_01 AC 72 ms
71,360 KB
testcase_02 AC 83 ms
76,512 KB
testcase_03 AC 140 ms
77,628 KB
testcase_04 AC 173 ms
77,592 KB
testcase_05 AC 113 ms
77,640 KB
testcase_06 AC 114 ms
77,352 KB
testcase_07 AC 156 ms
77,716 KB
testcase_08 AC 115 ms
77,420 KB
testcase_09 AC 169 ms
77,648 KB
testcase_10 AC 92 ms
76,388 KB
testcase_11 AC 133 ms
77,464 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)

for i in range(2,n):
    tmp = 2
    while tmp*i <= n:
        ki.union(i,tmp*i)
        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