結果

問題 No.1737 One to N
ユーザー shinichishinichi
提出日時 2021-11-13 19:38:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 576 bytes
コンパイル時間 1,067 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 8,736 KB
最終ジャッジ日時 2023-08-18 14:11:54
合計ジャッジ時間 2,890 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,692 KB
testcase_01 AC 17 ms
8,632 KB
testcase_02 AC 19 ms
8,700 KB
testcase_03 AC 18 ms
8,596 KB
testcase_04 AC 18 ms
8,532 KB
testcase_05 AC 17 ms
8,652 KB
testcase_06 AC 18 ms
8,588 KB
testcase_07 AC 18 ms
8,708 KB
testcase_08 AC 18 ms
8,584 KB
testcase_09 AC 18 ms
8,552 KB
testcase_10 AC 17 ms
8,552 KB
testcase_11 AC 17 ms
8,688 KB
testcase_12 AC 18 ms
8,528 KB
testcase_13 AC 17 ms
8,596 KB
testcase_14 AC 18 ms
8,564 KB
testcase_15 AC 17 ms
8,600 KB
testcase_16 AC 16 ms
8,556 KB
testcase_17 AC 17 ms
8,476 KB
testcase_18 AC 17 ms
8,736 KB
testcase_19 AC 17 ms
8,564 KB
testcase_20 AC 18 ms
8,712 KB
testcase_21 AC 18 ms
8,712 KB
testcase_22 AC 17 ms
8,556 KB
testcase_23 AC 18 ms
8,716 KB
testcase_24 AC 18 ms
8,652 KB
testcase_25 AC 17 ms
8,624 KB
testcase_26 AC 17 ms
8,648 KB
testcase_27 AC 17 ms
8,660 KB
testcase_28 AC 18 ms
8,640 KB
testcase_29 AC 17 ms
8,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache


def make_divisors(n):
    lower, upper = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower.append(i)
            if i != n // i:
                upper.append(n // i)
        i += 1
    return lower + upper[::-1]

@lru_cache(100000)
def solve(number):
    if number == 1:
        return 0
    divisors = make_divisors(number)
    res = 1001001001001
    for div in divisors:
        if div == number:
            continue
        res = min(res, number//div + solve(div))
    return res

print(solve(int(input())))
0