結果

問題 No.1059 素敵な集合
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-24 14:08:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,840 ms / 2,000 ms
コード長 498 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 276,072 KB
最終ジャッジ日時 2023-09-07 13:22:15
合計ジャッジ時間 9,176 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,420 KB
testcase_01 AC 71 ms
71,416 KB
testcase_02 AC 199 ms
107,424 KB
testcase_03 AC 70 ms
71,128 KB
testcase_04 AC 73 ms
71,396 KB
testcase_05 AC 71 ms
71,376 KB
testcase_06 AC 171 ms
96,168 KB
testcase_07 AC 169 ms
93,876 KB
testcase_08 AC 211 ms
108,972 KB
testcase_09 AC 123 ms
83,452 KB
testcase_10 AC 323 ms
120,632 KB
testcase_11 AC 173 ms
95,828 KB
testcase_12 AC 134 ms
88,844 KB
testcase_13 AC 329 ms
126,528 KB
testcase_14 AC 84 ms
76,292 KB
testcase_15 AC 603 ms
167,692 KB
testcase_16 AC 194 ms
104,608 KB
testcase_17 AC 188 ms
104,084 KB
testcase_18 AC 94 ms
91,864 KB
testcase_19 AC 1,678 ms
276,072 KB
testcase_20 AC 1,840 ms
263,888 KB
testcase_21 AC 545 ms
165,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main1(l,r):
  if l==1:return 0
  g=[set() for _ in range(r-l+1)]
  for i in range(l,r+1):
    ii=i+i
    while ii<=r:
      g[ii-l].add(i-l)
      g[i-l].add(ii-l)
      ii+=i
  mi=set(range(r-l+1))
  ans=0
  while mi:
    ans+=1
    v0=mi.pop()
    todo=[v0]
    while todo:
      v=todo.pop()
      for nv in g[v]:
        if nv in mi:
          todo.append(nv)
          mi.discard(nv)
  return ans-1

if __name__=='__main__':
  l,r=map(int,input().split())
  ret1=main1(l,r)
  print(ret1)

0