結果

問題 No.390 最長の数列
ユーザー matsu7874matsu7874
提出日時 2016-07-11 00:48:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,169 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 38,772 KB
最終ジャッジ日時 2024-04-21 12:10:52
合計ジャッジ時間 12,075 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
10,752 KB
testcase_01 AC 26 ms
10,752 KB
testcase_02 AC 25 ms
10,624 KB
testcase_03 AC 24 ms
10,624 KB
testcase_04 AC 24 ms
10,624 KB
testcase_05 AC 4,579 ms
33,620 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
import functools
import operator
def prime_decomposition(n):
    if n < 2:
        return []
    prime_factors = []
    while n % 2 == 0:
        prime_factors.append(2)
        n >>= 1
    while n % 3 == 0:
        prime_factors.append(3)
        n //= 3
    a = 5
    b = 7
    while a ** 2 <= n:
        if n % a == 0:
            prime_factors.append(a)
            n //= a
        elif n % b == 0:
            prime_factors.append(b)
            n //= b
        else:
            a += 6
            b += 6
    if n > 1:
        prime_factors.append(n)
    return prime_factors


def get_divisor(n):
    divisor = [1]
    prime_divisor = prime_decomposition(n)
    divisor = [1] + prime_divisor
    for i in range(2, len(prime_divisor)+1):
        for d in itertools.combinations(prime_divisor, r=i):
            divisor.append(functools.reduce(operator.mul, d))
    return divisor


n = int(input())
x = list(map(int, input().split()))
x.sort()
length = [0 for i in range(max(x) + 1)]
max_length = 1
for e in x:
    length[e] = max(length[e], *[length[d] + 1 for d in get_divisor(e)])
    max_length = max(max_length, length[e])
print(max_length)
0