結果

問題 No.1711 Divide LCM
ユーザー chineristACchineristAC
提出日時 2021-08-06 23:19:50
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,341 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 81,656 KB
実行使用メモリ 74,316 KB
最終ジャッジ日時 2023-10-17 19:46:02
合計ジャッジ時間 12,908 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 WA -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 WA -
testcase_09 WA -
testcase_10 RE -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 RE -
testcase_39 WA -
testcase_40 AC 55 ms
69,304 KB
testcase_41 AC 55 ms
69,304 KB
testcase_42 AC 55 ms
69,304 KB
testcase_43 AC 55 ms
69,304 KB
testcase_44 AC 55 ms
69,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

M = 10**3
spf = [i for i in range(M+1)]
for i in range(2,M+1):
    if spf[i]==i:
        for j in range(2*i,M+1,i):
            spf[j] = i
prime = [i for i in range(2,M+1) if spf[i]==i]

def factorization(n):
    assert 1<=n<=10**6
    res = {}
    for p in prime:
        cnt = 0
        while n%p==0:
            cnt += 1
            n //= p
        if cnt:
            res[p] = cnt
    if n!=1:
        res[n] = 1
    return res

def divisors(M):
    d=[]
    i=1
    while M>=i**2:
        if M%i==0:
            d.append(i)
            if i**2!=M:
                d.append(M//i)
        i=i+1
    return d

from collections import deque

N = int(input())
A = list(map(int,input().split()))

M = 10**6
pre = [0 for i in range(M+1)]
all_divisors = set()
for a in A:
    a_prime = factorization(a)
    for p in a_prime:
        pre[p] = max(pre[p],pow(p,a_prime[p]))
    div = divisors(a)
    for d in div:
        all_divisors.add(d)

P = [val for val in pre if val!=0][::-1]
n = len(P)

p = [P[0]]
prod = P[0]
for i in range(1,n):
    p.append(P[i])
    prod *= P[i]
    if M < prod:
        break
else:
    exit(print(-1))

k = len(p)
S = [[] for i in range(k)]
for a in A:
    for i in range(k):
        if a%p[i]:
            S[i].append(a)
            break
print(k)
for i in range(k):
    S[i] = [len(S[i])] + S[i]
    print(*S[i])
0