結果

問題 No.826 連絡網
ユーザー sho_00sho_00
提出日時 2020-04-09 21:02:32
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 753 bytes
コンパイル時間 679 ms
コンパイル使用メモリ 86,868 KB
実行使用メモリ 92,356 KB
最終ジャッジ日時 2023-10-11 21:30:47
合計ジャッジ時間 6,393 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
76,012 KB
testcase_01 AC 94 ms
71,296 KB
testcase_02 AC 108 ms
77,304 KB
testcase_03 AC 129 ms
77,768 KB
testcase_04 AC 137 ms
77,460 KB
testcase_05 AC 122 ms
77,660 KB
testcase_06 AC 122 ms
77,352 KB
testcase_07 AC 133 ms
77,400 KB
testcase_08 AC 121 ms
77,636 KB
testcase_09 AC 136 ms
77,448 KB
testcase_10 AC 115 ms
77,200 KB
testcase_11 AC 128 ms
77,176 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 #

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

def primenumber_table(N):  # N以下の素数テーブル エラトステネスの篩
  table=[i for i in range(2,N+1)]
  l=[]
  while len(table)!=0:
    num=table[0]
    l.append(num)
    i=0
    while i<len(table):
      if table[i]%num==0:
        table.pop(i)
      else:
        i+=1
  return l

if P==1:
  print(1)
else:
  E=[[] for _ in range(N)]
  table=primenumber_table(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