結果

問題 No.826 連絡網
ユーザー hedwig100hedwig100
提出日時 2020-04-20 14:43:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,591 ms / 2,000 ms
コード長 771 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 261,188 KB
最終ジャッジ日時 2024-04-16 00:41:53
合計ジャッジ時間 15,846 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
53,504 KB
testcase_01 AC 47 ms
53,632 KB
testcase_02 AC 54 ms
60,416 KB
testcase_03 AC 75 ms
67,968 KB
testcase_04 AC 73 ms
68,736 KB
testcase_05 AC 65 ms
65,536 KB
testcase_06 AC 69 ms
65,664 KB
testcase_07 AC 73 ms
68,352 KB
testcase_08 AC 69 ms
66,304 KB
testcase_09 AC 72 ms
68,864 KB
testcase_10 AC 64 ms
64,384 KB
testcase_11 AC 70 ms
67,200 KB
testcase_12 AC 1,025 ms
222,752 KB
testcase_13 AC 358 ms
132,736 KB
testcase_14 AC 850 ms
176,592 KB
testcase_15 AC 135 ms
86,784 KB
testcase_16 AC 555 ms
145,460 KB
testcase_17 AC 419 ms
133,632 KB
testcase_18 AC 340 ms
118,016 KB
testcase_19 AC 1,316 ms
239,800 KB
testcase_20 AC 1,131 ms
247,864 KB
testcase_21 AC 76 ms
70,016 KB
testcase_22 AC 447 ms
130,944 KB
testcase_23 AC 596 ms
149,344 KB
testcase_24 AC 283 ms
106,368 KB
testcase_25 AC 1,445 ms
260,956 KB
testcase_26 AC 327 ms
113,024 KB
testcase_27 AC 1,117 ms
225,508 KB
testcase_28 AC 910 ms
186,336 KB
testcase_29 AC 431 ms
129,024 KB
testcase_30 AC 1,591 ms
261,188 KB
testcase_31 AC 542 ms
141,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque

def main():
    n, P = map(int,input().split())
    G = [[] for _ in range(n + 1)]
    primes = [1] * (n + 1)
    for p in range(2,n + 1):
        if primes[p]:
            for i in range(2 * p,n + 1,p):
                primes[i] = 0
                G[i].append(p)
                G[p].append(i)
    
    stack = []
    stack.append(P)
    visited = [0] * (n + 1)
    visited[P] = 1
    while stack:
        p = stack.pop()
        for v in G[p]:
            if visited[v]:
                continue
            else:
                visited[v] = 1
                stack.append(v)
    
    print(sum(visited))

if __name__ == '__main__':
    main()
0