結果

問題 No.1059 素敵な集合
ユーザー takakintakakin
提出日時 2020-05-22 23:39:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 579 bytes
コンパイル時間 397 ms
コンパイル使用メモリ 87,188 KB
実行使用メモリ 78,640 KB
最終ジャッジ日時 2023-09-30 15:34:46
合計ジャッジ時間 4,056 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,356 KB
testcase_01 AC 112 ms
77,756 KB
testcase_02 AC 124 ms
77,784 KB
testcase_03 AC 73 ms
71,324 KB
testcase_04 AC 74 ms
71,408 KB
testcase_05 AC 73 ms
71,412 KB
testcase_06 AC 119 ms
77,312 KB
testcase_07 AC 119 ms
77,668 KB
testcase_08 AC 122 ms
77,692 KB
testcase_09 AC 119 ms
77,316 KB
testcase_10 AC 122 ms
77,892 KB
testcase_11 AC 123 ms
77,676 KB
testcase_12 AC 146 ms
77,848 KB
testcase_13 AC 127 ms
77,816 KB
testcase_14 AC 82 ms
76,056 KB
testcase_15 AC 139 ms
78,640 KB
testcase_16 AC 122 ms
77,884 KB
testcase_17 AC 124 ms
77,796 KB
testcase_18 AC 80 ms
76,652 KB
testcase_19 AC 129 ms
77,728 KB
testcase_20 AC 141 ms
78,632 KB
testcase_21 AC 136 ms
78,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
l,r=map(int,input().split())
n=r-l+1
par=[-1]*n

def find(x):
  if par[x]<0:
    return x
  else:
    par[x]=find(par[x])
    return par[x]

def unite(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return False
  else:
    if par[x]>par[y]:
      x,y=y,x
    par[x]+=par[y]
    par[y]=x
    return True

def same(x,y):
  return find(x)==find(y)

def size(x):
  return -par[find(x)]

for i in range(l,r+1):
  mul=2
  while mul*i<=r:
    unite(i-l,i*mul-l)
    mul+=1
ct=0
for i in range(n):
  if par[i]<0:
    ct+=1
print(ct-1)
0