結果

問題 No.1059 素敵な集合
ユーザー takakintakakin
提出日時 2020-05-22 23:39:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,704 ms / 2,000 ms
コード長 579 bytes
コンパイル時間 131 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 14,720 KB
最終ジャッジ日時 2024-04-15 19:13:29
合計ジャッジ時間 8,550 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,496 KB
testcase_01 AC 1,704 ms
12,160 KB
testcase_02 AC 152 ms
12,160 KB
testcase_03 AC 30 ms
10,624 KB
testcase_04 AC 30 ms
10,496 KB
testcase_05 AC 29 ms
10,752 KB
testcase_06 AC 128 ms
11,520 KB
testcase_07 AC 129 ms
11,520 KB
testcase_08 AC 168 ms
12,160 KB
testcase_09 AC 52 ms
10,880 KB
testcase_10 AC 287 ms
12,160 KB
testcase_11 AC 143 ms
11,520 KB
testcase_12 AC 76 ms
11,136 KB
testcase_13 AC 292 ms
12,800 KB
testcase_14 AC 31 ms
10,752 KB
testcase_15 AC 537 ms
14,208 KB
testcase_16 AC 154 ms
11,904 KB
testcase_17 AC 130 ms
11,904 KB
testcase_18 AC 73 ms
11,264 KB
testcase_19 AC 1,540 ms
12,288 KB
testcase_20 AC 1,486 ms
12,288 KB
testcase_21 AC 503 ms
14,720 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