結果
問題 | No.1059 素敵な集合 |
ユーザー |
![]() |
提出日時 | 2020-05-22 21:58:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,545 ms / 2,000 ms |
コード長 | 1,077 bytes |
コンパイル時間 | 166 ms |
コンパイル使用メモリ | 82,340 KB |
実行使用メモリ | 95,776 KB |
最終ジャッジ日時 | 2024-07-23 09:29:10 |
合計ジャッジ時間 | 14,851 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
import sysinput = sys.stdin.readlineimport mathdef facts(x):xr=math.ceil(math.sqrt(x))LIST=[]for i in range(1,xr+1):if x%i==0:LIST.append(i)LIST.append(x//i)return sorted(set(LIST))L,R=map(int,input().split())# UnionFindGroup = [i for i in range(2*10**5+1)] # グループ分けNodes = [1]*(2*10**5+1) # 各グループのノードの数def find(x):while Group[x] != x:x=Group[x]return xdef Union(x,y):if find(x) != find(y):if Nodes[find(x)] < Nodes[find(y)]:Nodes[find(y)] += Nodes[find(x)]Nodes[find(x)] = 0Group[find(x)] = find(y)else:Nodes[find(x)] += Nodes[find(y)]Nodes[find(y)] = 0Group[find(y)] = find(x)for i in range(L):Union(i,0)for i in range(R+1,2*10**5+1):Union(i,0)for i in range(R,L-1,-1):LIST=[j for j in facts(i) if j>=L]for j in LIST:Union(i,j)print(len(set([find(i) for i in range(2*10**5+1)]))-2)