結果

問題 No.826 連絡網
ユーザー brthyyjpbrthyyjp
提出日時 2020-09-01 04:32:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 323 ms / 2,000 ms
コード長 1,044 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 82,172 KB
実行使用メモリ 99,572 KB
最終ジャッジ日時 2024-04-28 15:31:26
合計ジャッジ時間 6,341 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
67,140 KB
testcase_01 AC 61 ms
68,452 KB
testcase_02 AC 64 ms
71,840 KB
testcase_03 AC 78 ms
78,540 KB
testcase_04 AC 77 ms
78,676 KB
testcase_05 AC 74 ms
77,036 KB
testcase_06 AC 76 ms
77,544 KB
testcase_07 AC 78 ms
78,780 KB
testcase_08 AC 76 ms
78,284 KB
testcase_09 AC 78 ms
79,756 KB
testcase_10 AC 74 ms
76,504 KB
testcase_11 AC 79 ms
78,304 KB
testcase_12 AC 248 ms
95,296 KB
testcase_13 AC 144 ms
88,784 KB
testcase_14 AC 201 ms
91,856 KB
testcase_15 AC 93 ms
84,932 KB
testcase_16 AC 160 ms
89,536 KB
testcase_17 AC 145 ms
88,304 KB
testcase_18 AC 130 ms
87,520 KB
testcase_19 AC 277 ms
96,808 KB
testcase_20 AC 273 ms
96,352 KB
testcase_21 AC 79 ms
80,048 KB
testcase_22 AC 144 ms
88,240 KB
testcase_23 AC 166 ms
89,092 KB
testcase_24 AC 113 ms
86,168 KB
testcase_25 AC 322 ms
99,392 KB
testcase_26 AC 125 ms
86,936 KB
testcase_27 AC 255 ms
95,432 KB
testcase_28 AC 213 ms
92,596 KB
testcase_29 AC 144 ms
88,268 KB
testcase_30 AC 323 ms
99,572 KB
testcase_31 AC 159 ms
89,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, p = map(int, input().split())

import math

N = 10**6+50
spf = [-1]*(N+1)
for i in range(N+1):
    spf[i] = i
for i in range(2, int(math.sqrt(N))+1):
    if spf[i] == i:
        for j in range(i*2, N+1, i):
            if spf[j] == j:
                spf[j] = i

def Find(x, par):
    if par[x] < 0:
        return x
    else:
        par[x] = Find(par[x], par)
        return par[x]

def Unite(x, y, par, rank):
    x = Find(x, par)
    y = Find(y, par)

    if x != y:
        if rank[x] < rank[y]:
            par[y] += par[x]
            par[x] = y
        else:
            par[x] += par[y]
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1

def Same(x, y, par):
    return Find(x, par) == Find(y, par)

def Size(x, par):
    return -par[Find(x, par)]

par = [-1]*(n+1)
rank = [0]*(n+1)
for i in range(1, n+1):
    j = i
    s = set()
    while j != 1:
        q = spf[j]
        if q not in s:
            Unite(i, q, par, rank)
            s.add(q)
        j //= q
#print(par)
print(Size(p, par))
0