結果

問題 No.826 連絡網
ユーザー sho_00sho_00
提出日時 2020-04-09 21:13:34
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 762 bytes
コンパイル時間 1,334 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 267,252 KB
最終ジャッジ日時 2023-10-11 21:48:49
合計ジャッジ時間 23,087 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
71,812 KB
testcase_01 AC 96 ms
71,872 KB
testcase_02 AC 107 ms
77,328 KB
testcase_03 AC 118 ms
77,804 KB
testcase_04 AC 120 ms
77,776 KB
testcase_05 AC 118 ms
77,744 KB
testcase_06 AC 117 ms
77,636 KB
testcase_07 AC 121 ms
77,748 KB
testcase_08 AC 118 ms
77,720 KB
testcase_09 AC 122 ms
77,748 KB
testcase_10 AC 115 ms
77,564 KB
testcase_11 AC 122 ms
77,596 KB
testcase_12 AC 1,469 ms
245,336 KB
testcase_13 AC 536 ms
136,620 KB
testcase_14 AC 1,111 ms
191,676 KB
testcase_15 AC 183 ms
85,908 KB
testcase_16 AC 733 ms
149,972 KB
testcase_17 AC 568 ms
136,676 KB
testcase_18 AC 459 ms
121,936 KB
testcase_19 AC 1,748 ms
265,628 KB
testcase_20 AC 1,584 ms
265,148 KB
testcase_21 AC 125 ms
77,620 KB
testcase_22 AC 614 ms
136,884 KB
testcase_23 AC 756 ms
153,432 KB
testcase_24 AC 351 ms
107,368 KB
testcase_25 TLE -
testcase_26 AC 422 ms
115,012 KB
testcase_27 AC 1,529 ms
263,496 KB
testcase_28 AC 1,197 ms
200,752 KB
testcase_29 AC 559 ms
135,928 KB
testcase_30 TLE -
testcase_31 AC 720 ms
145,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import math
N,P=map(int,input().split())

def searchPrimeNum(N):
  max = int(math.sqrt(N))
  searchList = [i for i in range(2,N+1)]
  primeNum = []
  while searchList[0] <= max:
    primeNum.append(searchList[0])
    tmp = searchList[0]
    searchList = [i for i in searchList if i % tmp != 0]
  primeNum.extend(searchList)
  return primeNum

if P==1:
  print(1)
else:
  E=[[] for _ in range(N)]
  table=searchPrimeNum(N)
  for v in table:
    i=2
    while v*i<=N:
      E[v-1].append(v*i-1)
      E[v*i-1].append(v-1)
      i+=1
  P-=1
  seen=[0]*N
  seen[P]=1
  stack=deque([P])
  cnt=1
  while stack:
    u=stack.pop()
    for v in E[u]:
      if seen[v]!=1:
        seen[v]=1
        cnt+=1
        stack.append(v)
  print(cnt)
0