結果

問題 No.1581 Multiple Sequence
ユーザー FromBooskaFromBooska
提出日時 2023-10-11 12:55:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 621 ms / 2,000 ms
コード長 1,291 bytes
コンパイル時間 1,263 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 77,816 KB
最終ジャッジ日時 2023-10-11 12:55:40
合計ジャッジ時間 11,106 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,304 KB
testcase_01 AC 74 ms
71,332 KB
testcase_02 AC 473 ms
77,696 KB
testcase_03 AC 544 ms
77,644 KB
testcase_04 AC 178 ms
77,196 KB
testcase_05 AC 542 ms
77,616 KB
testcase_06 AC 287 ms
77,248 KB
testcase_07 AC 172 ms
77,104 KB
testcase_08 AC 214 ms
77,168 KB
testcase_09 AC 491 ms
77,712 KB
testcase_10 AC 360 ms
77,288 KB
testcase_11 AC 127 ms
77,252 KB
testcase_12 AC 229 ms
77,172 KB
testcase_13 AC 87 ms
76,408 KB
testcase_14 AC 551 ms
77,480 KB
testcase_15 AC 384 ms
77,532 KB
testcase_16 AC 140 ms
77,004 KB
testcase_17 AC 581 ms
77,584 KB
testcase_18 AC 120 ms
77,224 KB
testcase_19 AC 458 ms
77,676 KB
testcase_20 AC 482 ms
77,800 KB
testcase_21 AC 544 ms
77,632 KB
testcase_22 AC 306 ms
77,476 KB
testcase_23 AC 621 ms
77,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 1次元dp
# dp[i] 要素合計iで、要素すべてが1以上の整数で、すべてが倍数関係、のパターン数
# dp[1] = 1 for [1]
# dp[2] = 2 for [1, 1] and [2]
# dp[3] = 3 for [1, 1, 1], [1, 2], and [3]
# dp[4] = 5 for [1, 1, 1, 1], [1, 1, 2], [1, 3], [2, 2] and [4]
# dp[5] = 6 for [1, 1, 1, 1, 1], [1, 1, 1, 2], [1, 1, 3], [1, 2, 2], [1, 4], [5]
# 遷移が思いつかなかった
# 公式解説より、数列の第1項は常にiの約数であり、それをjとする
# jで始まる数列のすべての要素はjで割り切れ、jで割り切ると第1項は1となり、第2項以後の和はi//j-1となる
# そのパターン数はdp[i//j-1]

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

M = int(input())
mod = 10**9+7
dp = [0]*(max(10, M)+1)
dp[0] = 1 # ダミー、常にiが1つだけという数列がありうるから
dp[1] = 1
dp[2] = 2
dp[3] = 3
dp[4] = 5
dp[5] = 6
for i in range(6, M+1):
    divs = divisors(i)
    for j in divs:
        dp[i] += dp[i//j-1]
    dp[i] %= mod
#print(dp)
ans = dp[M]
print(ans)
0