結果

問題 No.1059 素敵な集合
ユーザー takakin
提出日時 2020-05-22 23:39:26
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,751 ms / 2,000 ms
コード長 579 bytes
コンパイル時間 234 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 14,592 KB
最終ジャッジ日時 2024-10-05 21:44:28
合計ジャッジ時間 8,958 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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