結果

問題 No.1059 素敵な集合
ユーザー titiatitia
提出日時 2020-05-22 21:58:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,690 ms / 2,000 ms
コード長 1,077 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 87,188 KB
実行使用メモリ 96,864 KB
最終ジャッジ日時 2023-09-30 15:28:50
合計ジャッジ時間 17,161 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 188 ms
81,416 KB
testcase_01 AC 1,690 ms
83,028 KB
testcase_02 AC 603 ms
85,728 KB
testcase_03 AC 184 ms
81,392 KB
testcase_04 AC 184 ms
81,580 KB
testcase_05 AC 182 ms
81,640 KB
testcase_06 AC 457 ms
84,556 KB
testcase_07 AC 456 ms
83,388 KB
testcase_08 AC 588 ms
84,436 KB
testcase_09 AC 317 ms
83,808 KB
testcase_10 AC 632 ms
83,640 KB
testcase_11 AC 476 ms
84,060 KB
testcase_12 AC 376 ms
83,848 KB
testcase_13 AC 926 ms
85,508 KB
testcase_14 AC 245 ms
83,324 KB
testcase_15 AC 1,347 ms
85,844 KB
testcase_16 AC 531 ms
84,840 KB
testcase_17 AC 546 ms
84,580 KB
testcase_18 AC 896 ms
96,864 KB
testcase_19 AC 1,661 ms
83,092 KB
testcase_20 AC 1,639 ms
83,992 KB
testcase_21 AC 1,613 ms
85,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

import math

def 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())

# UnionFind

Group = [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 x

def Union(x,y):
    if find(x) != find(y):
        if Nodes[find(x)] < Nodes[find(y)]:
            
            Nodes[find(y)] += Nodes[find(x)]
            Nodes[find(x)] = 0
            Group[find(x)] = find(y)
            
        else:
            Nodes[find(x)] += Nodes[find(y)]
            Nodes[find(y)] = 0
            Group[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)
0