結果

問題 No.826 連絡網
ユーザー sho_00sho_00
提出日時 2020-04-09 20:59:22
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 736 bytes
コンパイル時間 562 ms
コンパイル使用メモリ 86,972 KB
実行使用メモリ 92,636 KB
最終ジャッジ日時 2023-10-11 21:30:35
合計ジャッジ時間 7,038 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
75,896 KB
testcase_01 AC 95 ms
71,840 KB
testcase_02 AC 112 ms
77,164 KB
testcase_03 AC 128 ms
77,488 KB
testcase_04 AC 142 ms
77,640 KB
testcase_05 AC 123 ms
77,500 KB
testcase_06 AC 125 ms
77,460 KB
testcase_07 AC 135 ms
77,372 KB
testcase_08 AC 122 ms
77,624 KB
testcase_09 AC 139 ms
77,660 KB
testcase_10 AC 119 ms
77,736 KB
testcase_11 AC 129 ms
77,536 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])
  while stack:
    u=stack.pop()
    for v in E[u]:
      if seen[v]!=1:
        seen[v]=1
        stack.append(v)
  print(sum(seen))
0